bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.200.872
by Jelmer Vernooij
Move refs code to separate module. |
1 |
# Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
17 |
"""Conversion between refs and Bazaar revision pointers."""
|
|
18 |
||
19 |
def extract_tags(refs): |
|
20 |
"""Extract the tags from a refs dictionary. |
|
21 |
||
22 |
:param refs: Refs to extract the tags from.
|
|
23 |
:return: Dictionary mapping tag names to SHA1s.
|
|
24 |
"""
|
|
25 |
ret = {} |
|
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 |
|
30 |
return ret |
|
31 |
||
32 |
||
33 |
def branch_name_to_ref(name, default=None): |
|
34 |
"""Map a branch name to a ref. |
|
35 |
||
36 |
:param name: Branch name
|
|
37 |
:return: ref string
|
|
38 |
"""
|
|
39 |
if name is None: |
|
40 |
return default |
|
41 |
if name == "HEAD": |
|
42 |
return "HEAD" |
|
43 |
if not name.startswith("refs/"): |
|
44 |
return "refs/heads/%s" % name |
|
45 |
else: |
|
46 |
return name |
|
47 |
||
48 |
||
49 |
def ref_to_branch_name(ref): |
|
50 |
"""Map a ref to a branch name |
|
51 |
||
52 |
:param ref: Ref
|
|
53 |
:return: A branch name
|
|
54 |
"""
|
|
55 |
if ref == "HEAD": |
|
56 |
return "HEAD" |
|
57 |
if ref.startswith("refs/heads/"): |
|
58 |
return ref[len("refs/heads/"):] |
|
59 |
raise ValueError("unable to map ref %s back to branch name") |
|
60 |
||
61 |