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

Fix support for older versions of Dulwich.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
"""Custom revision specifier for Subversion."""
17
17
 
18
 
# Please note that imports are delayed as much as possible here since
 
18
# Please note that imports are delayed as much as possible here since 
19
19
# if DWIM revspecs are supported this module is imported by __init__.py.
20
20
 
21
21
from bzrlib.errors import (
22
22
    InvalidRevisionId,
23
23
    InvalidRevisionSpec,
24
24
    )
25
 
from bzrlib.revision import (
26
 
    NULL_REVISION,
27
 
)
28
25
from bzrlib.revisionspec import (
29
26
    RevisionInfo,
30
27
    RevisionSpec,
32
29
 
33
30
 
34
31
def valid_git_sha1(hex):
35
 
    """Check if `hex` is a validly formatted Git SHA1.
36
 
    
37
 
    :param hex: Hex string to validate
38
 
    :return: Boolean
39
 
    """
40
32
    import binascii
41
33
    try:
42
34
        binascii.unhexlify(hex)
51
43
 
52
44
    help_txt = """Selects a revision using a Git revision sha1.
53
45
    """
54
 
 
 
46
    
55
47
    prefix = 'git:'
56
48
    wants_revision_history = False
57
49
 
59
51
        from bzrlib.plugins.git.errors import (
60
52
            GitSmartRemoteNotSupported,
61
53
            )
62
 
        from bzrlib.plugins.git.mapping import (
63
 
            default_mapping,
64
 
            )
65
54
 
66
 
        bzr_revid = getattr(branch.repository, "lookup_foreign_revision_id",
67
 
                              default_mapping.revision_id_foreign_to_bzr)(sha1)
 
55
        bzr_revid = branch.mapping.revision_id_foreign_to_bzr(sha1)
68
56
        try:
69
57
            if branch.repository.has_revision(bzr_revid):
70
58
                history = self._history(branch, bzr_revid)
74
62
        raise InvalidRevisionSpec(self.user_spec, branch)
75
63
 
76
64
    def _history(self, branch, revid):
77
 
        branch.lock_read()
78
 
        try:
79
 
            history = list(branch.repository.iter_reverse_revision_history(
80
 
                revid))
81
 
        finally:
82
 
            branch.unlock()
 
65
        history = list(branch.repository.iter_reverse_revision_history(revid))
83
66
        history.reverse()
84
67
        return history
85
68
 
86
69
    def __nonzero__(self):
 
70
        from bzrlib.revision import (
 
71
            NULL_REVISION,
 
72
            )
87
73
        # The default implementation uses branch.repository.has_revision()
88
74
        if self.rev_id is None:
89
75
            return False
93
79
 
94
80
    def _find_short_git_sha1(self, branch, sha1):
95
81
        from bzrlib.plugins.git.mapping import (
96
 
            ForeignGit,
97
82
            mapping_registry,
98
83
            )
99
84
        parse_revid = getattr(branch.repository, "lookup_bzr_revision_id",
102
87
        try:
103
88
            graph = branch.repository.get_graph()
104
89
            for revid, _ in graph.iter_ancestry([branch.last_revision()]):
105
 
                if revid == NULL_REVISION:
106
 
                    continue
107
90
                try:
108
91
                    foreign_revid, mapping = parse_revid(revid)
109
92
                except InvalidRevisionId:
110
93
                    continue
111
 
                if not isinstance(mapping.vcs, ForeignGit):
112
 
                    continue
113
94
                if foreign_revid.startswith(sha1):
114
95
                    history = self._history(branch, revid)
115
96
                    return RevisionInfo.from_revision_id(branch, revid, history)