/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: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

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
    )
40
38
    :param hex: Hex string to validate
41
39
    :return: Boolean
42
40
    """
43
 
    import binascii
44
41
    try:
45
 
        binascii.unhexlify(hex)
46
 
    except TypeError:
47
 
        return False
48
 
    except binascii.Error:
 
42
        int(hex, 16)
 
43
    except ValueError:
49
44
        return False
50
45
    else:
51
46
        return True
52
47
 
53
48
 
54
49
class RevisionSpec_git(RevisionSpec):
55
 
    """Selects a revision using a Subversion revision number."""
56
 
 
57
 
    help_txt = """Selects a revision using a Git revision sha1.
 
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.
58
58
    """
59
59
 
60
60
    prefix = 'git:'
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
 
        if len(git_sha1) > 40 or not valid_git_sha1(git_sha1):
114
 
            raise InvalidRevisionSpec(self.user_spec, branch)
 
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)
115
121
        from . import (
116
122
            lazy_check_versions,
117
123
            )
118
124
        lazy_check_versions()
119
125
        if len(git_sha1) == 40:
120
 
            return self._lookup_git_sha1(branch, git_sha1)
 
126
            return self._lookup_git_sha1(context_branch, git_sha1)
121
127
        else:
122
 
            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)
123
133
 
124
134
    def needs_branch(self):
125
135
        return True