/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

Add FOSDEM roundtripping notes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
 
38
38
class BzrFetchGraphWalker(object):
 
39
    """GraphWalker implementation that uses a Bazaar repository."""
39
40
 
40
41
    def __init__(self, repository, mapping):
41
42
        self.repository = repository
44
45
        self.heads = set(repository.all_revision_ids())
45
46
        self.parents = {}
46
47
 
 
48
    def __iter__(self):
 
49
        return iter(self.next, None)
 
50
 
47
51
    def ack(self, sha):
48
52
        revid = self.mapping.revision_id_foreign_to_bzr(sha)
49
53
        self.remove(revid)
122
126
            raise AssertionError("Unknown blob kind, perms=%r." % (mode,))
123
127
 
124
128
 
125
 
def import_git_objects(repo, mapping, num_objects, object_iter, pb=None):
 
129
def import_git_objects(repo, mapping, object_iter, pb=None):
126
130
    """Import a set of git objects into a bzr repository.
127
131
 
128
132
    :param repo: Bazaar repository
129
133
    :param mapping: Mapping to use
130
 
    :param num_objects: Number of objects.
131
134
    :param object_iter: Iterator over Git objects.
132
135
    """
133
136
    # TODO: a more (memory-)efficient implementation of this
134
 
    objects = {}
135
 
    for i, (o, _) in enumerate(object_iter):
136
 
        if pb is not None:
137
 
            pb.update("fetching objects", i, num_objects) 
138
 
        objects[o.id] = o
139
137
    graph = []
140
138
    root_trees = {}
141
139
    revisions = {}
142
140
    # Find and convert commit objects
143
 
    for o in objects.itervalues():
 
141
    for o in object_iter.iterobjects():
144
142
        if isinstance(o, Commit):
145
143
            rev = mapping.import_commit(o)
146
 
            root_trees[rev.revision_id] = objects[o.tree]
 
144
            root_trees[rev.revision_id] = object_iter[o.tree]
147
145
            revisions[rev.revision_id] = rev
148
146
            graph.append((rev.revision_id, rev.parent_ids))
149
147
    # Order the revisions
159
157
        inv = Inventory()
160
158
        inv.revision_id = rev.revision_id
161
159
        def lookup_object(sha):
162
 
            if sha in objects:
163
 
                return objects[sha]
 
160
            if sha in object_iter:
 
161
                return object_iter[sha]
164
162
            return reconstruct_git_object(repo, mapping, sha)
165
163
        parent_invs = [repo.get_inventory(r) for r in rev.parent_ids]
166
164
        import_git_tree(repo, mapping, "", root_tree, inv, parent_invs, 
220
218
            try:
221
219
                self.target.start_write_group()
222
220
                try:
223
 
                    (num_objects, objects_iter) = \
224
 
                            self.source.fetch_objects(determine_wants, 
 
221
                    objects_iter = self.source.fetch_objects(determine_wants, 
225
222
                                graph_walker, progress)
226
 
                    import_git_objects(self.target, mapping, num_objects, 
227
 
                                       objects_iter, pb)
 
223
                    import_git_objects(self.target, mapping, objects_iter, pb)
228
224
                finally:
229
225
                    self.target.commit_write_group()
230
226
            finally: