/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/mapping.py

  • Committer: Breezy landing bot
  • Author(s): Gustav Hartvigsson
  • Date: 2021-01-10 18:46:30 UTC
  • mfrom: (7526.1.1 brz-removed-api-doc)
  • mto: This revision was merged to the branch mainline in revision 7532.
  • Revision ID: breezy.the.bot@gmail.com-20210110184630-dxu0g9dqq020uiw6
Drop documentation for removed API API.

Merged from https://code.launchpad.net/~gustav-hartvigsson/brz/removed-api-doc/+merge/396033

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
    if b"<" not in text and b">" not in text:
115
115
        username = text
116
116
        email = text
 
117
    elif b">" not in text:
 
118
        return text + b">"
117
119
    else:
118
120
        if text.rindex(b">") < text.rindex(b"<"):
119
121
            raise ValueError(text)
124
126
    return b"%s <%s>" % (username, email)
125
127
 
126
128
 
 
129
def decode_git_path(path):
 
130
    """Take a git path and decode it."""
 
131
    try:
 
132
        return path.decode('utf-8')
 
133
    except UnicodeDecodeError:
 
134
        if PY3:
 
135
            return path.decode('utf-8', 'surrogateescape')
 
136
        raise
 
137
 
 
138
 
 
139
def encode_git_path(path):
 
140
    """Take a regular path and encode it for git."""
 
141
    try:
 
142
        return path.encode('utf-8')
 
143
    except UnicodeEncodeError:
 
144
        if PY3:
 
145
            return path.encode('utf-8', 'surrogateescape')
 
146
        raise
 
147
 
 
148
 
127
149
def warn_escaped(commit, num_escaped):
128
150
    trace.warning("Escaped %d XML-invalid characters in %s. Will be unable "
129
151
                  "to regenerate the SHA map.", num_escaped, commit)
138
160
    """Class that maps between Git and Bazaar semantics."""
139
161
    experimental = False
140
162
 
141
 
    BZR_DUMMY_FILE = None
 
163
    BZR_DUMMY_FILE = None  # type: Optional[str]
142
164
 
143
165
    def is_special_file(self, filename):
144
166
        return (filename in (self.BZR_DUMMY_FILE, ))
179
201
            return u""
180
202
        if not file_id.startswith(FILE_ID_PREFIX):
181
203
            raise ValueError
182
 
        return unescape_file_id(file_id[len(FILE_ID_PREFIX):]).decode('utf-8')
183
 
 
184
 
    def revid_as_refname(self, revid):
185
 
        if not isinstance(revid, bytes):
186
 
            raise TypeError(revid)
187
 
        revid = revid.decode('utf-8')
188
 
        quoted_revid = urlutils.quote(revid)
189
 
        return b"refs/bzr/" + quoted_revid.encode('utf-8')
 
204
        return decode_git_path(unescape_file_id(file_id[len(FILE_ID_PREFIX):]))
190
205
 
191
206
    def import_unusual_file_modes(self, rev, unusual_file_modes):
192
207
        if unusual_file_modes:
324
339
            commit.author_timezone = commit.commit_timezone
325
340
        if u'git-gpg-signature' in rev.properties:
326
341
            commit.gpgsig = rev.properties[u'git-gpg-signature'].encode(
327
 
                'ascii')
 
342
                'utf-8', 'surrogateescape')
328
343
        commit.message = self._encode_commit_message(rev, rev.message,
329
344
                                                     encoding)
330
345
        if not isinstance(commit.message, bytes):
420
435
            rev.properties[u'commit-timezone-neg-utc'] = ""
421
436
        if commit.gpgsig:
422
437
            rev.properties[u'git-gpg-signature'] = commit.gpgsig.decode(
423
 
                'ascii')
 
438
                'utf-8', 'surrogateescape')
424
439
        if commit.mergetag:
425
440
            for i, tag in enumerate(commit.mergetag):
426
441
                rev.properties[u'git-mergetag-%d' % i] = tag.as_raw_string()
567
582
    from dulwich.objects import Blob
568
583
    blob = Blob()
569
584
    if isinstance(symlink_target, str):
570
 
        symlink_target = symlink_target.encode('utf-8')
 
585
        symlink_target = encode_git_path(symlink_target)
571
586
    blob.data = symlink_target
572
587
    return blob
573
588