/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

More tests for sha maps, fix cache misses in tdb.

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
19
 
# if DWIM revspecs are supported this module is imported by __init__.py.
20
 
 
21
18
from bzrlib.errors import (
 
19
    BzrError,
22
20
    InvalidRevisionId,
23
21
    InvalidRevisionSpec,
 
22
    NoSuchRevision,
 
23
    )
 
24
from bzrlib.revision import (
 
25
    NULL_REVISION,
24
26
    )
25
27
from bzrlib.revisionspec import (
26
28
    RevisionInfo,
27
29
    RevisionSpec,
28
30
    )
29
31
 
30
 
 
31
 
def valid_git_sha1(hex):
32
 
    import binascii
33
 
    try:
34
 
        binascii.unhexlify(hex)
35
 
    except TypeError:
36
 
        return False
37
 
    else:
38
 
        return True
39
 
 
 
32
from bzrlib.plugins.git import (
 
33
    lazy_check_versions,
 
34
    )
 
35
from bzrlib.plugins.git.errors import (
 
36
    GitSmartRemoteNotSupported,
 
37
    )
 
38
from bzrlib.plugins.git.mapping import (
 
39
    mapping_registry,
 
40
    )
40
41
 
41
42
class RevisionSpec_git(RevisionSpec):
42
43
    """Selects a revision using a Subversion revision number."""
43
44
 
44
45
    help_txt = """Selects a revision using a Git revision sha1.
45
46
    """
46
 
 
 
47
    
47
48
    prefix = 'git:'
48
49
    wants_revision_history = False
49
50
 
50
51
    def _lookup_git_sha1(self, branch, sha1):
51
 
        from bzrlib.plugins.git.errors import (
52
 
            GitSmartRemoteNotSupported,
53
 
            )
54
 
 
55
52
        bzr_revid = branch.mapping.revision_id_foreign_to_bzr(sha1)
56
53
        try:
57
54
            if branch.repository.has_revision(bzr_revid):
67
64
        return history
68
65
 
69
66
    def __nonzero__(self):
70
 
        from bzrlib.revision import (
71
 
            NULL_REVISION,
72
 
            )
73
67
        # The default implementation uses branch.repository.has_revision()
74
68
        if self.rev_id is None:
75
69
            return False
78
72
        return True
79
73
 
80
74
    def _find_short_git_sha1(self, branch, sha1):
81
 
        from bzrlib.plugins.git.mapping import (
82
 
            mapping_registry,
83
 
            )
84
 
        parse_revid = getattr(branch.repository, "lookup_bzr_revision_id",
 
75
        parse_revid = getattr(branch.repository, "lookup_git_revid",
85
76
                              mapping_registry.parse_revision_id)
86
77
        branch.repository.lock_read()
87
78
        try:
99
90
            branch.repository.unlock()
100
91
 
101
92
    def _match_on(self, branch, revs):
 
93
        lazy_check_versions()
102
94
        loc = self.spec.find(':')
103
95
        git_sha1 = self.spec[loc+1:].encode("utf-8")
104
 
        if len(git_sha1) > 40 or not valid_git_sha1(git_sha1):
105
 
            raise InvalidRevisionSpec(self.user_spec, branch)
106
 
        from bzrlib.plugins.git import (
107
 
            lazy_check_versions,
108
 
            )
109
 
        lazy_check_versions()
110
96
        if len(git_sha1) == 40:
111
97
            return self._lookup_git_sha1(branch, git_sha1)
 
98
        elif len(git_sha1) > 40:
 
99
            raise InvalidRevisionSpec(self.user_spec, branch)
112
100
        else:
113
101
            return self._find_short_git_sha1(branch, git_sha1)
114
102