1
# Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Conversion between refs and Bazaar revision pointers."""
19
def extract_tags(refs):
20
"""Extract the tags from a refs dictionary.
22
:param refs: Refs to extract the tags from.
23
:return: Dictionary mapping tag names to SHA1s.
26
for k,v in refs.iteritems():
27
if k.startswith("refs/tags/") and not k.endswith("^{}"):
28
v = refs.get(k+"^{}", v)
29
ret[k[len("refs/tags/"):]] = v
33
def branch_name_to_ref(name, default=None):
34
"""Map a branch name to a ref.
36
:param name: Branch name
43
if not name.startswith("refs/"):
44
return "refs/heads/%s" % name
49
def ref_to_branch_name(ref):
50
"""Map a ref to a branch name
53
:return: A branch name
57
if ref.startswith("refs/heads/"):
58
return ref[len("refs/heads/"):]
59
raise ValueError("unable to map ref %s back to branch name")