/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: Jelmer Vernooij
  • Date: 2009-03-16 13:56:04 UTC
  • mto: (0.200.259 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090316135604-9nkd7d2ztiygybiy
Strip ref directory name from tag names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Canonical Ltd
 
1
# Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
2
2
#
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
16
16
 
17
 
from bzrlib import osutils, ui, urlutils
18
 
from bzrlib.errors import InvalidRevisionId, NoSuchRevision
 
17
from cStringIO import StringIO
 
18
import dulwich as git
 
19
from dulwich.client import SimpleFetchGraphWalker
 
20
from dulwich.objects import Commit
 
21
 
 
22
from bzrlib import (
 
23
    osutils,
 
24
    ui,
 
25
    urlutils,
 
26
    )
 
27
from bzrlib.errors import (
 
28
    InvalidRevisionId,
 
29
    NoSuchRevision,
 
30
    )
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
31
43
 
32
 
import dulwich as git
33
 
from dulwich.client import SimpleFetchGraphWalker
34
 
from dulwich.objects import Commit
35
 
 
36
 
from cStringIO import StringIO
37
44
 
38
45
 
39
46
class BzrFetchGraphWalker(object):
213
220
                create_pb.finished()
214
221
 
215
222
    def fetch(self, revision_id=None, pb=None, find_ghosts=False, 
216
 
              mapping=None):
 
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)
 
226
 
 
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:
221
 
                ret = heads.values()
 
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
 
235
        else:
 
236
            interesting_heads = None
 
237
        self._refs = {}
 
238
        def determine_wants(refs):
 
239
            self._refs = refs
 
240
            if interesting_heads is None:
 
241
                ret = [sha for (ref, sha) in refs.iteritems() if not ref.endswith("^{}")]
222
242
            else:
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)
 
246
        return self._refs
226
247
 
227
248
    @staticmethod
228
249
    def is_compatible(source, target):
246
267
        self.fetch(revision_id, pb, find_ghosts=False)
247
268
 
248
269
    def fetch(self, revision_id=None, pb=None, find_ghosts=False, 
249
 
              mapping=None):
 
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]
257
 
        else:
 
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
 
282
        else:
259
283
            determine_wants = lambda x: [y for y in args if not y in r.object_store]
260
284
 
261
285
        graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents)