/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 some more tests.

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 (
29
29
 
30
30
 
31
31
def valid_git_sha1(hex):
 
32
    """Check if `hex` is a validly formatted Git SHA1.
 
33
    
 
34
    :param hex: Hex string to validate
 
35
    :return: Boolean
 
36
    """
32
37
    import binascii
33
38
    try:
34
39
        binascii.unhexlify(hex)
43
48
 
44
49
    help_txt = """Selects a revision using a Git revision sha1.
45
50
    """
46
 
    
 
51
 
47
52
    prefix = 'git:'
48
53
    wants_revision_history = False
49
54
 
51
56
        from bzrlib.plugins.git.errors import (
52
57
            GitSmartRemoteNotSupported,
53
58
            )
 
59
        from bzrlib.plugins.git.mapping import (
 
60
            default_mapping,
 
61
            )
54
62
 
55
 
        bzr_revid = branch.mapping.revision_id_foreign_to_bzr(sha1)
 
63
        bzr_revid = getattr(branch.repository, "lookup_foreign_revision_id",
 
64
                              default_mapping.revision_id_foreign_to_bzr)(sha1)
56
65
        try:
57
66
            if branch.repository.has_revision(bzr_revid):
58
67
                history = self._history(branch, bzr_revid)
62
71
        raise InvalidRevisionSpec(self.user_spec, branch)
63
72
 
64
73
    def _history(self, branch, revid):
65
 
        history = list(branch.repository.iter_reverse_revision_history(revid))
 
74
        branch.lock_read()
 
75
        try:
 
76
            history = list(branch.repository.iter_reverse_revision_history(
 
77
                revid))
 
78
        finally:
 
79
            branch.unlock()
66
80
        history.reverse()
67
81
        return history
68
82
 
79
93
 
80
94
    def _find_short_git_sha1(self, branch, sha1):
81
95
        from bzrlib.plugins.git.mapping import (
 
96
            ForeignGit,
82
97
            mapping_registry,
83
98
            )
84
99
        parse_revid = getattr(branch.repository, "lookup_bzr_revision_id",
91
106
                    foreign_revid, mapping = parse_revid(revid)
92
107
                except InvalidRevisionId:
93
108
                    continue
 
109
                if not isinstance(mapping.vcs, ForeignGit):
 
110
                    continue
94
111
                if foreign_revid.startswith(sha1):
95
112
                    history = self._history(branch, revid)
96
113
                    return RevisionInfo.from_revision_id(branch, revid, history)