/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

MergeĀ upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
        )
30
30
from bzrlib.plugins.git.remote import RemoteGitRepository
31
31
 
 
32
from dulwich.client import SimpleFetchGraphWalker
32
33
from dulwich.objects import Commit
33
34
 
34
35
from cStringIO import StringIO
49
50
 
50
51
    def remove(self, revid):
51
52
        self.done.add(revid)
52
 
        if ref in self.heads:
 
53
        if revid in self.heads:
53
54
            self.heads.remove(revid)
54
55
        if revid in self.parents:
55
56
            for p in self.parents[revid]:
121
122
            raise AssertionError("Unknown blob kind, perms=%r." % (mode,))
122
123
 
123
124
 
124
 
def import_git_objects(repo, mapping, object_iter, pb=None):
 
125
def import_git_objects(repo, mapping, num_objects, object_iter, pb=None):
125
126
    """Import a set of git objects into a bzr repository.
126
127
 
127
128
    :param repo: Bazaar repository
128
129
    :param mapping: Mapping to use
 
130
    :param num_objects: Number of objects.
129
131
    :param object_iter: Iterator over Git objects.
130
132
    """
131
133
    # TODO: a more (memory-)efficient implementation of this
132
134
    objects = {}
133
135
    for i, o in enumerate(object_iter):
134
136
        if pb is not None:
135
 
            pb.update("fetching objects", i) 
 
137
            pb.update("fetching objects", i, num_objects) 
136
138
        objects[o.id] = o
137
139
    graph = []
138
140
    root_trees = {}
161
163
                return objects[sha]
162
164
            return reconstruct_git_object(repo, mapping, sha)
163
165
        parent_invs = [repo.get_inventory(r) for r in rev.parent_ids]
164
 
        import_git_tree(repo, mapping, "", root_tree, inv, parent_invs, lookup_object)
 
166
        import_git_tree(repo, mapping, "", root_tree, inv, parent_invs, 
 
167
            lookup_object)
165
168
        repo.add_revision(rev.revision_id, rev, inv)
166
169
 
167
170
 
184
187
    raise KeyError("No such object %s" % sha)
185
188
 
186
189
 
187
 
class InterGitRepository(InterRepository):
 
190
class InterGitNonGitRepository(InterRepository):
188
191
 
189
192
    _matching_repo_format = GitFormat()
190
193
 
201
204
        if mapping is None:
202
205
            mapping = self.source.get_mapping()
203
206
        def progress(text):
204
 
            pb.note("git: %s", text)
 
207
            pb.update("git: %s" % text.rstrip("\r\n"), 0, 0)
205
208
        def determine_wants(heads):
206
209
            if revision_id is None:
207
210
                ret = heads.values()
217
220
            try:
218
221
                self.target.start_write_group()
219
222
                try:
220
 
                    import_git_objects(self.target, mapping,
221
 
                        iter(self.source.fetch_objects(determine_wants, graph_walker, 
222
 
                            progress)), pb)
 
223
                    (num_objects, objects_iter) = \
 
224
                            self.source.fetch_objects(determine_wants, 
 
225
                                graph_walker, progress)
 
226
                    import_git_objects(self.target, mapping, num_objects, 
 
227
                                       objects_iter, pb)
223
228
                finally:
224
229
                    self.target.commit_write_group()
225
230
            finally:
233
238
        """Be compatible with GitRepository."""
234
239
        # FIXME: Also check target uses VersionedFile
235
240
        return (isinstance(source, GitRepository) and 
236
 
                target.supports_rich_root())
 
241
                target.supports_rich_root() and
 
242
                not isinstance(target, GitRepository))
 
243
 
 
244
 
 
245
class InterGitRepository(InterRepository):
 
246
 
 
247
    _matching_repo_format = GitFormat()
 
248
 
 
249
    @staticmethod
 
250
    def _get_repo_format_to_test():
 
251
        return None
 
252
 
 
253
    def copy_content(self, revision_id=None, pb=None):
 
254
        """See InterRepository.copy_content."""
 
255
        self.fetch(revision_id, pb, find_ghosts=False)
 
256
 
 
257
    def fetch(self, revision_id=None, pb=None, find_ghosts=False, 
 
258
              mapping=None):
 
259
        if mapping is None:
 
260
            mapping = self.source.get_mapping()
 
261
        def progress(text):
 
262
            info("git: %s", text)
 
263
        r = self.target._git
 
264
        if revision_id is None:
 
265
            determine_wants = lambda x: [y for y in x.values() if not y in r.object_store]
 
266
        else:
 
267
            args = [mapping.revision_id_bzr_to_foreign(revision_id)]
 
268
            determine_wants = lambda x: [y for y in args if not y in r.object_store]
 
269
 
 
270
        graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents)
 
271
        f, commit = r.object_store.add_pack()
 
272
        try:
 
273
            self.source._git.fetch_pack(path, determine_wants, graphwalker, f.write, progress)
 
274
            f.close()
 
275
            commit()
 
276
        except:
 
277
            f.close()
 
278
            raise
 
279
 
 
280
    @staticmethod
 
281
    def is_compatible(source, target):
 
282
        """Be compatible with GitRepository."""
 
283
        return (isinstance(source, GitRepository) and 
 
284
                isinstance(target, GitRepository))