/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 optimized handling when fetching from git to git.

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
161
162
                return objects[sha]
162
163
            return reconstruct_git_object(repo, mapping, sha)
163
164
        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)
 
165
        import_git_tree(repo, mapping, "", root_tree, inv, parent_invs, 
 
166
            lookup_object)
165
167
        repo.add_revision(rev.revision_id, rev, inv)
166
168
 
167
169
 
184
186
    raise KeyError("No such object %s" % sha)
185
187
 
186
188
 
187
 
class InterGitRepository(InterRepository):
 
189
class InterGitNonGitRepository(InterRepository):
188
190
 
189
191
    _matching_repo_format = GitFormat()
190
192
 
233
235
        """Be compatible with GitRepository."""
234
236
        # FIXME: Also check target uses VersionedFile
235
237
        return (isinstance(source, GitRepository) and 
236
 
                target.supports_rich_root())
 
238
                target.supports_rich_root() and
 
239
                not isinstance(target, GitRepository))
 
240
 
 
241
 
 
242
class InterGitRepository(InterRepository):
 
243
 
 
244
    _matching_repo_format = GitFormat()
 
245
 
 
246
    @staticmethod
 
247
    def _get_repo_format_to_test():
 
248
        return None
 
249
 
 
250
    def copy_content(self, revision_id=None, pb=None):
 
251
        """See InterRepository.copy_content."""
 
252
        self.fetch(revision_id, pb, find_ghosts=False)
 
253
 
 
254
    def fetch(self, revision_id=None, pb=None, find_ghosts=False, 
 
255
              mapping=None):
 
256
        if mapping is None:
 
257
            mapping = self.source.get_mapping()
 
258
        def progress(text):
 
259
            info("git: %s", text)
 
260
        r = self.target._git
 
261
        if revision_id is None:
 
262
            determine_wants = lambda x: [y for y in x.values() if not y in r.object_store]
 
263
        else:
 
264
            args = [mapping.revision_id_bzr_to_foreign(revision_id)]
 
265
            determine_wants = lambda x: [y for y in args if not y in r.object_store]
 
266
 
 
267
        graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents)
 
268
        f, commit = r.object_store.add_pack()
 
269
        try:
 
270
            self.source._git.fetch_pack(path, determine_wants, graphwalker, f.write, progress)
 
271
            f.close()
 
272
            commit()
 
273
        except:
 
274
            f.close()
 
275
            raise
 
276
 
 
277
    @staticmethod
 
278
    def is_compatible(source, target):
 
279
        """Be compatible with GitRepository."""
 
280
        return (isinstance(source, GitRepository) and 
 
281
                isinstance(target, GitRepository))