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

  • Committer: Jelmer Vernooij
  • Date: 2020-02-18 01:57:45 UTC
  • mto: This revision was merged to the branch mainline in revision 7493.
  • Revision ID: jelmer@jelmer.uk-20200218015745-q2ss9tsk74h4nh61
drop use of future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from ..errors import (
23
23
    InvalidRevisionId,
 
24
    InvalidRevisionSpec,
24
25
    )
25
26
from ..revision import (
26
27
    NULL_REVISION,
27
28
)
28
29
from ..revisionspec import (
29
 
    InvalidRevisionSpec,
30
30
    RevisionInfo,
31
31
    RevisionSpec,
32
32
    )
72
72
                            default_mapping.revision_id_foreign_to_bzr)(sha1)
73
73
        try:
74
74
            if branch.repository.has_revision(bzr_revid):
75
 
                return bzr_revid
 
75
                return RevisionInfo.from_revision_id(branch, bzr_revid)
76
76
        except GitSmartRemoteNotSupported:
77
 
            return bzr_revid
 
77
            return RevisionInfo(branch, None, bzr_revid)
78
78
        raise InvalidRevisionSpec(self.user_spec, branch)
79
79
 
80
80
    def __nonzero__(self):
92
92
            )
93
93
        parse_revid = getattr(branch.repository, "lookup_bzr_revision_id",
94
94
                              mapping_registry.parse_revision_id)
95
 
        def matches_revid(revid):
96
 
            if revid == NULL_REVISION:
97
 
                return False
98
 
            try:
99
 
                foreign_revid, mapping = parse_revid(revid)
100
 
            except InvalidRevisionId:
101
 
                return False
102
 
            if not isinstance(mapping.vcs, ForeignGit):
103
 
                return False
104
 
            return foreign_revid.startswith(sha1)
105
95
        with branch.repository.lock_read():
106
96
            graph = branch.repository.get_graph()
107
 
            last_revid = branch.last_revision()
108
 
            if matches_revid(last_revid):
109
 
                return last_revid
110
 
            for revid, _ in graph.iter_ancestry([last_revid]):
111
 
                if matches_revid(revid):
112
 
                    return revid
 
97
            for revid, _ in graph.iter_ancestry([branch.last_revision()]):
 
98
                if revid == NULL_REVISION:
 
99
                    continue
 
100
                try:
 
101
                    foreign_revid, mapping = parse_revid(revid)
 
102
                except InvalidRevisionId:
 
103
                    continue
 
104
                if not isinstance(mapping.vcs, ForeignGit):
 
105
                    continue
 
106
                if foreign_revid.startswith(sha1):
 
107
                    return RevisionInfo.from_revision_id(branch, revid)
113
108
            raise InvalidRevisionSpec(self.user_spec, branch)
114
109
 
115
 
    def _as_revision_id(self, context_branch):
 
110
    def _match_on(self, branch, revs):
116
111
        loc = self.spec.find(':')
117
112
        git_sha1 = self.spec[loc + 1:].encode("utf-8")
118
113
        if (len(git_sha1) > 40 or len(git_sha1) < 4 or
119
114
                not valid_git_sha1(git_sha1)):
120
 
            raise InvalidRevisionSpec(self.user_spec, context_branch)
 
115
            raise InvalidRevisionSpec(self.user_spec, branch)
121
116
        from . import (
122
117
            lazy_check_versions,
123
118
            )
124
119
        lazy_check_versions()
125
120
        if len(git_sha1) == 40:
126
 
            return self._lookup_git_sha1(context_branch, git_sha1)
 
121
            return self._lookup_git_sha1(branch, git_sha1)
127
122
        else:
128
 
            return self._find_short_git_sha1(context_branch, git_sha1)
129
 
 
130
 
    def _match_on(self, branch, revs):
131
 
        revid = self._as_revision_id(branch)
132
 
        return RevisionInfo.from_revision_id(branch, revid)
 
123
            return self._find_short_git_sha1(branch, git_sha1)
133
124
 
134
125
    def needs_branch(self):
135
126
        return True