/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: Jelmer Vernooij
  • Date: 2020-07-18 23:14:00 UTC
  • mfrom: (7490.40.62 work)
  • mto: This revision was merged to the branch mainline in revision 7519.
  • Revision ID: jelmer@jelmer.uk-20200718231400-jaes9qltn8oi8xss
Merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
    return b"%s <%s>" % (username, email)
127
127
 
128
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
 
129
149
def warn_escaped(commit, num_escaped):
130
150
    trace.warning("Escaped %d XML-invalid characters in %s. Will be unable "
131
151
                  "to regenerate the SHA map.", num_escaped, commit)
181
201
            return u""
182
202
        if not file_id.startswith(FILE_ID_PREFIX):
183
203
            raise ValueError
184
 
        return unescape_file_id(file_id[len(FILE_ID_PREFIX):]).decode('utf-8')
185
 
 
186
 
    def revid_as_refname(self, revid):
187
 
        if not isinstance(revid, bytes):
188
 
            raise TypeError(revid)
189
 
        revid = revid.decode('utf-8')
190
 
        quoted_revid = urlutils.quote(revid)
191
 
        return b"refs/bzr/" + quoted_revid.encode('utf-8')
 
204
        return decode_git_path(unescape_file_id(file_id[len(FILE_ID_PREFIX):]))
192
205
 
193
206
    def import_unusual_file_modes(self, rev, unusual_file_modes):
194
207
        if unusual_file_modes:
326
339
            commit.author_timezone = commit.commit_timezone
327
340
        if u'git-gpg-signature' in rev.properties:
328
341
            commit.gpgsig = rev.properties[u'git-gpg-signature'].encode(
329
 
                'utf-8')
330
 
        if u'git-gpg-signature-b64' in rev.properties:
331
 
            commit.gpgsig = base64.b64decode(rev.properties[u'git-gpg-signature-b64'])
 
342
                'utf-8', 'surrogateescape')
332
343
        commit.message = self._encode_commit_message(rev, rev.message,
333
344
                                                     encoding)
334
345
        if not isinstance(commit.message, bytes):
341
352
            mapping_properties = set(
342
353
                [u'author', u'author-timezone', u'author-timezone-neg-utc',
343
354
                 u'commit-timezone-neg-utc', u'git-implicit-encoding',
344
 
                 u'git-gpg-signature', u'git-gpg-signature-b64',
345
 
                 u'git-explicit-encoding',
 
355
                 u'git-gpg-signature', u'git-explicit-encoding',
346
356
                 u'author-timestamp', u'file-modes'])
347
357
            for k, v in rev.properties.items():
348
358
                if k not in mapping_properties:
424
434
        if commit._commit_timezone_neg_utc:
425
435
            rev.properties[u'commit-timezone-neg-utc'] = ""
426
436
        if commit.gpgsig:
427
 
            try:
428
 
                rev.properties[u'git-gpg-signature'] = commit.gpgsig.decode(
429
 
                    'utf-8')
430
 
            except UnicodeDecodeError:
431
 
                rev.properties[u'git-gpg-signature-b64'] = base64.b64encode(
432
 
                    commit.gpgsig)
 
437
            rev.properties[u'git-gpg-signature'] = commit.gpgsig.decode(
 
438
                'utf-8', 'surrogateescape')
433
439
        if commit.mergetag:
434
440
            for i, tag in enumerate(commit.mergetag):
435
441
                rev.properties[u'git-mergetag-%d' % i] = tag.as_raw_string()
576
582
    from dulwich.objects import Blob
577
583
    blob = Blob()
578
584
    if isinstance(symlink_target, str):
579
 
        symlink_target = symlink_target.encode('utf-8')
 
585
        symlink_target = encode_git_path(symlink_target)
580
586
    blob.data = symlink_target
581
587
    return blob
582
588