/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: 2019-03-05 07:32:38 UTC
  • mto: (7290.1.21 work)
  • mto: This revision was merged to the branch mainline in revision 7311.
  • Revision ID: jelmer@jelmer.uk-20190305073238-zlqn981opwnqsmzi
Add appveyor configuration.

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
    )
47
49
 
48
50
 
49
51
class RevisionSpec_git(RevisionSpec):
50
 
    """Selects a revision using a Git commit SHA1."""
51
 
 
52
 
    help_txt = """Selects a revision using a Git commit SHA1.
53
 
 
54
 
    Selects a revision using a Git commit SHA1, short or long.
55
 
 
56
 
    This works for both native Git repositories and Git revisions
57
 
    imported into Bazaar repositories.
 
52
    """Selects a revision using a Subversion revision number."""
 
53
 
 
54
    help_txt = """Selects a revision using a Git revision sha1.
58
55
    """
59
56
 
60
57
    prefix = 'git:'
72
69
                            default_mapping.revision_id_foreign_to_bzr)(sha1)
73
70
        try:
74
71
            if branch.repository.has_revision(bzr_revid):
75
 
                return bzr_revid
 
72
                return RevisionInfo.from_revision_id(branch, bzr_revid)
76
73
        except GitSmartRemoteNotSupported:
77
 
            return bzr_revid
 
74
            return RevisionInfo(branch, None, bzr_revid)
78
75
        raise InvalidRevisionSpec(self.user_spec, branch)
79
76
 
80
77
    def __nonzero__(self):
92
89
            )
93
90
        parse_revid = getattr(branch.repository, "lookup_bzr_revision_id",
94
91
                              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
92
        with branch.repository.lock_read():
106
93
            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
 
94
            for revid, _ in graph.iter_ancestry([branch.last_revision()]):
 
95
                if revid == NULL_REVISION:
 
96
                    continue
 
97
                try:
 
98
                    foreign_revid, mapping = parse_revid(revid)
 
99
                except InvalidRevisionId:
 
100
                    continue
 
101
                if not isinstance(mapping.vcs, ForeignGit):
 
102
                    continue
 
103
                if foreign_revid.startswith(sha1):
 
104
                    return RevisionInfo.from_revision_id(branch, revid)
113
105
            raise InvalidRevisionSpec(self.user_spec, branch)
114
106
 
115
 
    def _as_revision_id(self, context_branch):
 
107
    def _match_on(self, branch, revs):
116
108
        loc = self.spec.find(':')
117
109
        git_sha1 = self.spec[loc + 1:].encode("utf-8")
118
 
        if (len(git_sha1) > 40 or len(git_sha1) < 4 or
119
 
                not valid_git_sha1(git_sha1)):
120
 
            raise InvalidRevisionSpec(self.user_spec, context_branch)
 
110
        if len(git_sha1) > 40 or not valid_git_sha1(git_sha1):
 
111
            raise InvalidRevisionSpec(self.user_spec, branch)
121
112
        from . import (
122
113
            lazy_check_versions,
123
114
            )
124
115
        lazy_check_versions()
125
116
        if len(git_sha1) == 40:
126
 
            return self._lookup_git_sha1(context_branch, git_sha1)
 
117
            return self._lookup_git_sha1(branch, git_sha1)
127
118
        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)
 
119
            return self._find_short_git_sha1(branch, git_sha1)
133
120
 
134
121
    def needs_branch(self):
135
122
        return True