/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 work on roundtrip push support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    InvalidRevisionId,
23
23
    InvalidRevisionSpec,
24
24
    )
 
25
from bzrlib.revision import (
 
26
    NULL_REVISION,
 
27
)
25
28
from bzrlib.revisionspec import (
26
29
    RevisionInfo,
27
30
    RevisionSpec,
29
32
 
30
33
 
31
34
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
    """
32
40
    import binascii
33
41
    try:
34
42
        binascii.unhexlify(hex)
51
59
        from bzrlib.plugins.git.errors import (
52
60
            GitSmartRemoteNotSupported,
53
61
            )
 
62
        from bzrlib.plugins.git.mapping import (
 
63
            default_mapping,
 
64
            )
54
65
 
55
 
        bzr_revid = branch.mapping.revision_id_foreign_to_bzr(sha1)
 
66
        bzr_revid = getattr(branch.repository, "lookup_foreign_revision_id",
 
67
                              default_mapping.revision_id_foreign_to_bzr)(sha1)
56
68
        try:
57
69
            if branch.repository.has_revision(bzr_revid):
58
70
                history = self._history(branch, bzr_revid)
62
74
        raise InvalidRevisionSpec(self.user_spec, branch)
63
75
 
64
76
    def _history(self, branch, revid):
65
 
        history = list(branch.repository.iter_reverse_revision_history(revid))
 
77
        branch.lock_read()
 
78
        try:
 
79
            history = list(branch.repository.iter_reverse_revision_history(
 
80
                revid))
 
81
        finally:
 
82
            branch.unlock()
66
83
        history.reverse()
67
84
        return history
68
85
 
69
86
    def __nonzero__(self):
70
 
        from bzrlib.revision import (
71
 
            NULL_REVISION,
72
 
            )
73
87
        # The default implementation uses branch.repository.has_revision()
74
88
        if self.rev_id is None:
75
89
            return False
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",
87
102
        try:
88
103
            graph = branch.repository.get_graph()
89
104
            for revid, _ in graph.iter_ancestry([branch.last_revision()]):
 
105
                if revid == NULL_REVISION:
 
106
                    continue
90
107
                try:
91
108
                    foreign_revid, mapping = parse_revid(revid)
92
109
                except InvalidRevisionId:
93
110
                    continue
 
111
                if not isinstance(mapping.vcs, ForeignGit):
 
112
                    continue
94
113
                if foreign_revid.startswith(sha1):
95
114
                    history = self._history(branch, revid)
96
115
                    return RevisionInfo.from_revision_id(branch, revid, history)