/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): Jelmer Vernooij
  • Date: 2020-06-01 21:57:00 UTC
  • mfrom: (7490.39.3 move-launchpad)
  • Revision ID: breezy.the.bot@gmail.com-20200601215700-joxuzo6w172gq74v
Move launchpad hoster support to the launchpad plugin.

Merged from https://code.launchpad.net/~jelmer/brz/move-launchpad/+merge/384931

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">"
119
117
    else:
120
118
        if text.rindex(b">") < text.rindex(b"<"):
121
119
            raise ValueError(text)
126
124
    return b"%s <%s>" % (username, email)
127
125
 
128
126
 
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
 
 
149
127
def warn_escaped(commit, num_escaped):
150
128
    trace.warning("Escaped %d XML-invalid characters in %s. Will be unable "
151
129
                  "to regenerate the SHA map.", num_escaped, commit)
160
138
    """Class that maps between Git and Bazaar semantics."""
161
139
    experimental = False
162
140
 
163
 
    BZR_DUMMY_FILE = None  # type: Optional[str]
 
141
    BZR_DUMMY_FILE = None
164
142
 
165
143
    def is_special_file(self, filename):
166
144
        return (filename in (self.BZR_DUMMY_FILE, ))
201
179
            return u""
202
180
        if not file_id.startswith(FILE_ID_PREFIX):
203
181
            raise ValueError
204
 
        return decode_git_path(unescape_file_id(file_id[len(FILE_ID_PREFIX):]))
 
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')
205
190
 
206
191
    def import_unusual_file_modes(self, rev, unusual_file_modes):
207
192
        if unusual_file_modes:
339
324
            commit.author_timezone = commit.commit_timezone
340
325
        if u'git-gpg-signature' in rev.properties:
341
326
            commit.gpgsig = rev.properties[u'git-gpg-signature'].encode(
342
 
                'utf-8', 'surrogateescape')
 
327
                'utf-8')
 
328
        if u'git-gpg-signature-b64' in rev.properties:
 
329
            commit.gpgsig = base64.b64decode(rev.properties[u'git-gpg-signature-b64'])
343
330
        commit.message = self._encode_commit_message(rev, rev.message,
344
331
                                                     encoding)
345
332
        if not isinstance(commit.message, bytes):
352
339
            mapping_properties = set(
353
340
                [u'author', u'author-timezone', u'author-timezone-neg-utc',
354
341
                 u'commit-timezone-neg-utc', u'git-implicit-encoding',
355
 
                 u'git-gpg-signature', u'git-explicit-encoding',
 
342
                 u'git-gpg-signature', u'git-gpg-signature-b64',
 
343
                 u'git-explicit-encoding',
356
344
                 u'author-timestamp', u'file-modes'])
357
345
            for k, v in rev.properties.items():
358
346
                if k not in mapping_properties:
434
422
        if commit._commit_timezone_neg_utc:
435
423
            rev.properties[u'commit-timezone-neg-utc'] = ""
436
424
        if commit.gpgsig:
437
 
            rev.properties[u'git-gpg-signature'] = commit.gpgsig.decode(
438
 
                'utf-8', 'surrogateescape')
 
425
            try:
 
426
                rev.properties[u'git-gpg-signature'] = commit.gpgsig.decode(
 
427
                    'utf-8')
 
428
            except UnicodeDecodeError:
 
429
                rev.properties[u'git-gpg-signature-b64'] = base64.b64encode(
 
430
                    commit.gpgsig)
439
431
        if commit.mergetag:
440
432
            for i, tag in enumerate(commit.mergetag):
441
433
                rev.properties[u'git-mergetag-%d' % i] = tag.as_raw_string()
582
574
    from dulwich.objects import Blob
583
575
    blob = Blob()
584
576
    if isinstance(symlink_target, str):
585
 
        symlink_target = encode_git_path(symlink_target)
 
577
        symlink_target = symlink_target.encode('utf-8')
586
578
    blob.data = symlink_target
587
579
    return blob
588
580