/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 breezy/plugins/git/interrepo.py

  • Committer: Jelmer Vernooij
  • Date: 2018-06-15 11:45:41 UTC
  • mfrom: (6987.1.2 git-fixes)
  • Revision ID: jelmer@jelmer.uk-20180615114541-tphc7ioo53lun8sx
Merge lp:~jelmer/brz/git-fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    CAPABILITY_THIN_PACK,
31
31
    ZERO_SHA,
32
32
    )
 
33
from dulwich.refs import SYMREF
33
34
from dulwich.walk import Walker
34
35
 
35
36
from ...errors import (
230
231
        refs = {}
231
232
        for k in self.target._git.refs.allkeys():
232
233
            try:
233
 
                v = self.target._git.refs[k]
 
234
                v = self.target._git.refs.read_ref(k)
234
235
            except KeyError:
235
236
                # broken symref?
236
237
                continue
237
 
            try:
238
 
                for (kind, type_data) in self.source_store.lookup_git_sha(v):
239
 
                    if kind == "commit" and self.source.has_revision(type_data[0]):
240
 
                        revid = type_data[0]
241
 
                        break
242
 
                else:
243
 
                    revid = None
244
 
            except KeyError:
245
 
                revid = None
 
238
            revid = None
 
239
            if not v.startswith(SYMREF):
 
240
                try:
 
241
                    for (kind, type_data) in self.source_store.lookup_git_sha(v):
 
242
                        if kind == "commit" and self.source.has_revision(type_data[0]):
 
243
                            revid = type_data[0]
 
244
                            break
 
245
                except KeyError:
 
246
                    pass
246
247
            bzr_refs[k] = (v, revid)
247
248
        return bzr_refs
248
249
 
252
253
            old_refs = self._get_target_bzr_refs()
253
254
            new_refs = update_refs(old_refs)
254
255
            revidmap = self.fetch_objects(
255
 
                [(git_sha, bzr_revid) for (git_sha, bzr_revid) in new_refs.values() if git_sha is None or not git_sha.startswith('ref:')], lossy=lossy)
 
256
                [(git_sha, bzr_revid) for (git_sha, bzr_revid) in new_refs.values() if git_sha is None or not git_sha.startswith(SYMREF)], lossy=lossy)
256
257
            for name, (gitid, revid) in new_refs.iteritems():
257
258
                if gitid is None:
258
259
                    try:
259
260
                        gitid = revidmap[revid][0]
260
261
                    except KeyError:
261
262
                        gitid = self.source_store._lookup_revision_sha1(revid)
262
 
                if len(gitid) != 40 and not gitid.startswith('ref: '):
263
 
                    raise AssertionError("invalid ref contents: %r" % gitid)
264
 
                self.target_refs[name] = gitid
 
263
                if gitid.startswith(SYMREF):
 
264
                    self.target_refs.set_symbolic_ref(name, gitid[len(SYMREF):])
 
265
                else:
 
266
                    try:
 
267
                        old_git_id = old_refs[name][0]
 
268
                    except KeyError:
 
269
                        self.target_refs.add_if_new(name, gitid)
 
270
                    else:
 
271
                        self.target_refs.set_if_equals(name, old_git_id, gitid)
265
272
        return revidmap, old_refs, new_refs
266
273
 
267
274
    def fetch_objects(self, revs, lossy, limit=None):