/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to fetch.py

  • Committer: John Carr
  • Date: 2009-01-13 20:26:54 UTC
  • mto: (0.217.53 git-serve)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: john.carr@unrouted.co.uk-20090113202654-9hsels0a9r35o7u0
Rename upload-pack and receive-pack so they don't clash with the Git versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from bzrlib.trace import info
22
22
from bzrlib.tsort import topo_sort
23
23
 
 
24
from bzrlib.plugins.git import git
24
25
from bzrlib.plugins.git.repository import (
25
26
        LocalGitRepository, 
26
27
        GitRepository, 
28
29
        )
29
30
from bzrlib.plugins.git.remote import RemoteGitRepository
30
31
 
31
 
import dulwich as git
32
32
from dulwich.client import SimpleFetchGraphWalker
33
33
from dulwich.objects import Commit
34
34
 
36
36
 
37
37
 
38
38
class BzrFetchGraphWalker(object):
39
 
    """GraphWalker implementation that uses a Bazaar repository."""
40
39
 
41
40
    def __init__(self, repository, mapping):
42
41
        self.repository = repository
45
44
        self.heads = set(repository.all_revision_ids())
46
45
        self.parents = {}
47
46
 
48
 
    def __iter__(self):
49
 
        return iter(self.next, None)
50
 
 
51
47
    def ack(self, sha):
52
48
        revid = self.mapping.revision_id_foreign_to_bzr(sha)
53
49
        self.remove(revid)
68
64
            self.heads.update([p for p in ps if not p in self.done])
69
65
            try:
70
66
                self.done.add(ret)
71
 
                return self.mapping.revision_id_bzr_to_foreign(ret)[0]
 
67
                return self.mapping.revision_id_bzr_to_foreign(ret)
72
68
            except InvalidRevisionId:
73
69
                pass
74
70
        return None
126
122
            raise AssertionError("Unknown blob kind, perms=%r." % (mode,))
127
123
 
128
124
 
129
 
def import_git_objects(repo, mapping, num_objects, object_iter, pb=None):
 
125
def import_git_objects(repo, mapping, object_iter, pb=None):
130
126
    """Import a set of git objects into a bzr repository.
131
127
 
132
128
    :param repo: Bazaar repository
133
129
    :param mapping: Mapping to use
134
 
    :param num_objects: Number of objects.
135
130
    :param object_iter: Iterator over Git objects.
136
131
    """
137
132
    # TODO: a more (memory-)efficient implementation of this
138
133
    objects = {}
139
 
    for i, (o, _) in enumerate(object_iter):
 
134
    for i, o in enumerate(object_iter):
140
135
        if pb is not None:
141
 
            pb.update("fetching objects", i, num_objects) 
 
136
            pb.update("fetching objects", i) 
142
137
        objects[o.id] = o
143
138
    graph = []
144
139
    root_trees = {}
213
208
            if revision_id is None:
214
209
                ret = heads.values()
215
210
            else:
216
 
                ret = [mapping.revision_id_bzr_to_foreign(revision_id)[0]]
 
211
                ret = [mapping.revision_id_bzr_to_foreign(revision_id)]
217
212
            return [rev for rev in ret if not self.target.has_revision(mapping.revision_id_foreign_to_bzr(rev))]
218
213
        graph_walker = BzrFetchGraphWalker(self.target, mapping)
219
214
        create_pb = None
224
219
            try:
225
220
                self.target.start_write_group()
226
221
                try:
227
 
                    (num_objects, objects_iter) = \
228
 
                            self.source.fetch_objects(determine_wants, 
229
 
                                graph_walker, progress)
230
 
                    import_git_objects(self.target, mapping, num_objects, 
231
 
                                       objects_iter, pb)
 
222
                    import_git_objects(self.target, mapping,
 
223
                        iter(self.source.fetch_objects(determine_wants, graph_walker, 
 
224
                            progress)), pb)
232
225
                finally:
233
226
                    self.target.commit_write_group()
234
227
            finally:
268
261
        if revision_id is None:
269
262
            determine_wants = lambda x: [y for y in x.values() if not y in r.object_store]
270
263
        else:
271
 
            args = [mapping.revision_id_bzr_to_foreign(revision_id)[0]]
 
264
            args = [mapping.revision_id_bzr_to_foreign(revision_id)]
272
265
            determine_wants = lambda x: [y for y in args if not y in r.object_store]
273
266
 
274
267
        graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents)