/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-08-10 15:00:17 UTC
  • mfrom: (7490.40.99 work)
  • mto: This revision was merged to the branch mainline in revision 7521.
  • Revision ID: jelmer@jelmer.uk-20200810150017-vs7xnrd1vat4iktg
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
 
 
21
19
# Please note that imports are delayed as much as possible here since
22
20
# if DWIM revspecs are supported this module is imported by __init__.py.
23
21
 
24
22
from ..errors import (
25
23
    InvalidRevisionId,
26
 
    InvalidRevisionSpec,
27
24
    )
28
25
from ..revision import (
29
26
    NULL_REVISION,
30
27
)
31
28
from ..revisionspec import (
 
29
    InvalidRevisionSpec,
32
30
    RevisionInfo,
33
31
    RevisionSpec,
34
32
    )
74
72
                            default_mapping.revision_id_foreign_to_bzr)(sha1)
75
73
        try:
76
74
            if branch.repository.has_revision(bzr_revid):
77
 
                return RevisionInfo.from_revision_id(branch, bzr_revid)
 
75
                return bzr_revid
78
76
        except GitSmartRemoteNotSupported:
79
 
            return RevisionInfo(branch, None, bzr_revid)
 
77
            return bzr_revid
80
78
        raise InvalidRevisionSpec(self.user_spec, branch)
81
79
 
82
80
    def __nonzero__(self):
94
92
            )
95
93
        parse_revid = getattr(branch.repository, "lookup_bzr_revision_id",
96
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)
97
105
        with branch.repository.lock_read():
98
106
            graph = branch.repository.get_graph()
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)
 
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
110
113
            raise InvalidRevisionSpec(self.user_spec, branch)
111
114
 
112
 
    def _match_on(self, branch, revs):
 
115
    def _as_revision_id(self, context_branch):
113
116
        loc = self.spec.find(':')
114
117
        git_sha1 = self.spec[loc + 1:].encode("utf-8")
115
118
        if (len(git_sha1) > 40 or len(git_sha1) < 4 or
116
119
                not valid_git_sha1(git_sha1)):
117
 
            raise InvalidRevisionSpec(self.user_spec, branch)
 
120
            raise InvalidRevisionSpec(self.user_spec, context_branch)
118
121
        from . import (
119
122
            lazy_check_versions,
120
123
            )
121
124
        lazy_check_versions()
122
125
        if len(git_sha1) == 40:
123
 
            return self._lookup_git_sha1(branch, git_sha1)
 
126
            return self._lookup_git_sha1(context_branch, git_sha1)
124
127
        else:
125
 
            return self._find_short_git_sha1(branch, git_sha1)
 
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)
126
133
 
127
134
    def needs_branch(self):
128
135
        return True