17
17
"""Conversion between refs and Bazaar revision pointers."""
19
from collections import defaultdict
20
from cStringIO import StringIO
19
22
from dulwich.repo import (
23
26
from bzrlib import (
31
is_tag = lambda x: x.startswith("refs/tags/")
28
34
def extract_tags(refs):
29
35
"""Extract the tags from a refs dictionary.
31
37
:param refs: Refs to extract the tags from.
32
:return: Dictionary mapping tag names to SHA1s.
38
:return: Dictionary mapping tag names to SHA1s of the actual object
39
and unpeeled object SHA1s.
35
for k,v in refs.iteritems():
36
if k.startswith("refs/tags/") and not k.endswith("^{}"):
37
v = refs.get(k+"^{}", v)
42
for k, v in refs.iteritems():
43
if is_tag(k) and not k.endswith("^{}"):
45
peeled = refs[k+"^{}"]
39
51
tagname = ref_to_tag_name(k)
40
52
except UnicodeDecodeError:
55
ret[tagname] = (peeled, unpeeled)
85
97
def ref_to_tag_name(ref):
86
98
if ref.startswith("refs/tags/"):
87
99
return ref[len('refs/tags/'):].decode("utf-8")
88
raise ValueError("unable to map ref %s back to branch name" % ref)
100
raise ValueError("unable to map ref %s back to tag name" % ref)
91
103
class BazaarRefsContainer(RefsContainer):
169
181
target_branch.generate_revision_history(rev_id)
171
183
target_branch.unlock()
186
class UnpeelMap(object):
189
Keeps track of the unpeeled object id of tags.
193
self._map = defaultdict(set)
196
for k, v in m.iteritems():
197
self._map[k].update(v)
200
assert f.readline() == "unpeel map version 1\n"
201
for l in f.readlines():
202
(k, v) = l.split(":", 1)
203
self._map[k.strip()].add(v.strip())
206
f.write("unpeel map version 1\n")
207
for k, vs in self._map.iteritems():
209
f.write("%s: %s\n" % (k, v))
211
def save_in_repository(self, repository):
216
repository.control_transport.put_file("git-unpeel-map", f)
220
def re_unpeel_tag(self, new_git_sha, old_git_sha):
223
Bazaar can't store unpeeled refs so in order to prevent peeling
224
existing tags when pushing they are "re-peeled" here.
226
if old_git_sha is not None and old_git_sha in self._map[new_git_sha]:
227
trace.mutter("re-unpeeling %r to %r", new_git_sha, old_git_sha)
232
def from_repository(cls, repository):
233
"""Load the unpeel map for a repository.
237
m.load(repository.control_transport.get("git-unpeel-map"))
238
except errors.NoSuchFile: