/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-28 02:11:05 UTC
  • mfrom: (7490.40.78 work)
  • mto: This revision was merged to the branch mainline in revision 7520.
  • Revision ID: jelmer@jelmer.uk-20200728021105-fzq7g6f8bl1g0aet
Merge lp:brz/3.1.

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 RevisionInfo.from_revision_id(branch, bzr_revid)
 
75
                return bzr_revid
76
76
        except GitSmartRemoteNotSupported:
77
 
            return RevisionInfo(branch, None, bzr_revid)
 
77
            return 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)
95
105
        with branch.repository.lock_read():
96
106
            graph = branch.repository.get_graph()
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)
 
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
108
113
            raise InvalidRevisionSpec(self.user_spec, branch)
109
114
 
110
 
    def _match_on(self, branch, revs):
 
115
    def _as_revision_id(self, context_branch):
111
116
        loc = self.spec.find(':')
112
117
        git_sha1 = self.spec[loc + 1:].encode("utf-8")
113
118
        if (len(git_sha1) > 40 or len(git_sha1) < 4 or
114
119
                not valid_git_sha1(git_sha1)):
115
 
            raise InvalidRevisionSpec(self.user_spec, branch)
 
120
            raise InvalidRevisionSpec(self.user_spec, context_branch)
116
121
        from . import (
117
122
            lazy_check_versions,
118
123
            )
119
124
        lazy_check_versions()
120
125
        if len(git_sha1) == 40:
121
 
            return self._lookup_git_sha1(branch, git_sha1)
 
126
            return self._lookup_git_sha1(context_branch, git_sha1)
122
127
        else:
123
 
            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)
124
133
 
125
134
    def needs_branch(self):
126
135
        return True