/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 refs.py

Various minor fixes.

Merged from https://code.launchpad.net/~jelmer/brz-git/misc-2/+merge/342482

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from __future__ import absolute_import
20
20
 
 
21
from dulwich.refs import (
 
22
    ANNOTATED_TAG_SUFFIX,
 
23
    LOCAL_BRANCH_PREFIX,
 
24
    LOCAL_TAG_PREFIX,
 
25
    )
21
26
from dulwich.repo import (
22
27
    RefsContainer,
23
28
    )
28
33
    revision as _mod_revision,
29
34
    )
30
35
 
31
 
is_tag = lambda x: x.startswith("refs/tags/")
32
 
is_head = lambda x: x.startswith("refs/heads/")
33
 
is_peeled = lambda x: x.endswith("^{}")
 
36
is_tag = lambda x: x.startswith(LOCAL_TAG_PREFIX)
 
37
is_head = lambda x: x.startswith(LOCAL_BRANCH_PREFIX)
 
38
is_peeled = lambda x: x.endswith(ANNOTATED_TAG_SUFFIX)
34
39
 
35
40
 
36
41
def gather_peeled(refs):
39
44
        if is_peeled(k):
40
45
            continue
41
46
        try:
42
 
            peeled = refs[k+"^{}"]
 
47
            peeled = refs[k+ANNOTATED_TAG_SUFFIX]
43
48
            unpeeled = v
44
49
        except KeyError:
45
50
            peeled = v
57
62
    if name == "":
58
63
        return "HEAD"
59
64
    if not name.startswith("refs/"):
60
 
        return "refs/heads/%s" % osutils.safe_utf8(name)
 
65
        return LOCAL_BRANCH_PREFIX + osutils.safe_utf8(name)
61
66
    else:
62
67
        return osutils.safe_utf8(name)
63
68
 
68
73
    :param name: Tag name
69
74
    :return: ref string
70
75
    """
71
 
    return "refs/tags/%s" % osutils.safe_utf8(name)
 
76
    return LOCAL_TAG_PREFIX + osutils.safe_utf8(name)
72
77
 
73
78
 
74
79
def ref_to_branch_name(ref):
81
86
        return u""
82
87
    if ref is None:
83
88
        return ref
84
 
    if ref.startswith("refs/heads/"):
85
 
        return osutils.safe_unicode(ref[len("refs/heads/"):])
 
89
    if ref.startswith(LOCAL_BRANCH_PREFIX):
 
90
        return osutils.safe_unicode(ref[len(LOCAL_BRANCH_PREFIX):])
86
91
    raise ValueError("unable to map ref %s back to branch name" % ref)
87
92
 
88
93
 
89
94
def ref_to_tag_name(ref):
90
 
    if ref.startswith("refs/tags/"):
91
 
        return ref[len('refs/tags/'):].decode("utf-8")
 
95
    if ref.startswith(LOCAL_TAG_PREFIX):
 
96
        return ref[len(LOCAL_TAG_PREFIX):].decode("utf-8")
92
97
    raise ValueError("unable to map ref %s back to tag name" % ref)
93
98
 
94
99