1
# Copyright (C) 2008 Canonical Ltd
1
# Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
from bzrlib import osutils, ui, urlutils
18
from bzrlib.errors import InvalidRevisionId, NoSuchRevision
17
from cStringIO import StringIO
19
from dulwich.client import SimpleFetchGraphWalker
20
from dulwich.objects import Commit
27
from bzrlib.errors import (
19
31
from bzrlib.inventory import Inventory
20
32
from bzrlib.repository import InterRepository
21
33
from bzrlib.trace import info
29
41
from bzrlib.plugins.git.converter import GitObjectConverter
30
42
from bzrlib.plugins.git.remote import RemoteGitRepository
33
from dulwich.client import SimpleFetchGraphWalker
34
from dulwich.objects import Commit
36
from cStringIO import StringIO
39
46
class BzrFetchGraphWalker(object):
213
220
create_pb.finished()
215
222
def fetch(self, revision_id=None, pb=None, find_ghosts=False,
223
mapping=None, fetch_spec=None):
224
self.fetch_refs(revision_id=revision_id, pb=pb, find_ghosts=find_ghosts,
225
mapping=mapping, fetch_spec=fetch_spec)
227
def fetch_refs(self, revision_id=None, pb=None, find_ghosts=False,
228
mapping=None, fetch_spec=None):
217
229
if mapping is None:
218
230
mapping = self.source.get_mapping()
219
def determine_wants(heads):
220
if revision_id is None:
231
if revision_id is not None:
232
interesting_heads = [revision_id]
233
elif fetch_spec is not None:
234
interesting_heads = fetch_spec.heads
236
interesting_heads = None
238
def determine_wants(refs):
240
if interesting_heads is None:
241
ret = [sha for (ref, sha) in refs.iteritems() if not ref.endswith("^{}")]
223
ret = [mapping.revision_id_bzr_to_foreign(revision_id)[0]]
243
ret = [mapping.revision_id_bzr_to_foreign(revid)[0] for revid in interesting_heads]
224
244
return [rev for rev in ret if not self.target.has_revision(mapping.revision_id_foreign_to_bzr(rev))]
225
return self.fetch_objects(determine_wants, mapping, pb)
245
self.fetch_objects(determine_wants, mapping, pb)
228
249
def is_compatible(source, target):
246
267
self.fetch(revision_id, pb, find_ghosts=False)
248
269
def fetch(self, revision_id=None, pb=None, find_ghosts=False,
270
mapping=None, fetch_spec=None):
250
271
if mapping is None:
251
272
mapping = self.source.get_mapping()
252
273
def progress(text):
253
274
info("git: %s", text)
254
275
r = self.target._git
255
if revision_id is None:
256
determine_wants = lambda x: [y for y in x.values() if not y in r.object_store]
276
if revision_id is not None:
258
277
args = [mapping.revision_id_bzr_to_foreign(revision_id)[0]]
278
elif fetch_spec is not None:
279
args = [mapping.revision_id_bzr_to_foreign(revid)[0] for revid in fetch_spec.heads]
280
if fetch_spec is None and revision_id is None:
281
determine_wants = r.object_store.determine_wants_all
259
283
determine_wants = lambda x: [y for y in args if not y in r.object_store]
261
285
graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents)