/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-07-05 12:50:01 UTC
  • mfrom: (7490.40.46 work)
  • mto: (7490.40.48 work)
  • mto: This revision was merged to the branch mainline in revision 7519.
  • Revision ID: jelmer@jelmer.uk-20200705125001-7s3vo0p55szbbws7
Merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Custom revision specifier for Subversion."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
# Please note that imports are delayed as much as possible here since
20
22
# if DWIM revspecs are supported this module is imported by __init__.py.
21
23
 
22
24
from ..errors import (
23
25
    InvalidRevisionId,
 
26
    InvalidRevisionSpec,
24
27
    )
25
28
from ..revision import (
26
29
    NULL_REVISION,
27
30
)
28
31
from ..revisionspec import (
29
 
    InvalidRevisionSpec,
30
32
    RevisionInfo,
31
33
    RevisionSpec,
32
34
    )
72
74
                            default_mapping.revision_id_foreign_to_bzr)(sha1)
73
75
        try:
74
76
            if branch.repository.has_revision(bzr_revid):
75
 
                return bzr_revid
 
77
                return RevisionInfo.from_revision_id(branch, bzr_revid)
76
78
        except GitSmartRemoteNotSupported:
77
 
            return bzr_revid
 
79
            return RevisionInfo(branch, None, bzr_revid)
78
80
        raise InvalidRevisionSpec(self.user_spec, branch)
79
81
 
80
82
    def __nonzero__(self):
92
94
            )
93
95
        parse_revid = getattr(branch.repository, "lookup_bzr_revision_id",
94
96
                              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
97
        with branch.repository.lock_read():
106
98
            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
 
99
            for revid, _ in graph.iter_ancestry([branch.last_revision()]):
 
100
                if revid == NULL_REVISION:
 
101
                    continue
 
102
                try:
 
103
                    foreign_revid, mapping = parse_revid(revid)
 
104
                except InvalidRevisionId:
 
105
                    continue
 
106
                if not isinstance(mapping.vcs, ForeignGit):
 
107
                    continue
 
108
                if foreign_revid.startswith(sha1):
 
109
                    return RevisionInfo.from_revision_id(branch, revid)
113
110
            raise InvalidRevisionSpec(self.user_spec, branch)
114
111
 
115
 
    def _as_revision_id(self, context_branch):
 
112
    def _match_on(self, branch, revs):
116
113
        loc = self.spec.find(':')
117
114
        git_sha1 = self.spec[loc + 1:].encode("utf-8")
118
115
        if (len(git_sha1) > 40 or len(git_sha1) < 4 or
119
116
                not valid_git_sha1(git_sha1)):
120
 
            raise InvalidRevisionSpec(self.user_spec, context_branch)
 
117
            raise InvalidRevisionSpec(self.user_spec, branch)
121
118
        from . import (
122
119
            lazy_check_versions,
123
120
            )
124
121
        lazy_check_versions()
125
122
        if len(git_sha1) == 40:
126
 
            return self._lookup_git_sha1(context_branch, git_sha1)
 
123
            return self._lookup_git_sha1(branch, git_sha1)
127
124
        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)
 
125
            return self._find_short_git_sha1(branch, git_sha1)
133
126
 
134
127
    def needs_branch(self):
135
128
        return True