/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-07-20 02:17:05 UTC
  • mfrom: (7518.1.2 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200720021705-5f11tmo1hdqjxm6x
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/387628

Show diffs side-by-side

added added

removed removed

Lines of Context:
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