/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: Gustav Hartvigsson
  • Date: 2021-01-11 20:19:38 UTC
  • mfrom: (7526.3.2 work)
  • Revision ID: gustav.hartvigsson@gmail.com-20210111201938-omr9wjz3qdgyxe8k
MergedĀ lp:brz

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
 
                'utf-8')
328
 
        if u'git-gpg-signature-b64' in rev.properties:
329
 
            commit.gpgsig = base64.b64decode(rev.properties[u'git-gpg-signature-b64'])
 
342
                'utf-8', 'surrogateescape')
330
343
        commit.message = self._encode_commit_message(rev, rev.message,
331
344
                                                     encoding)
332
345
        if not isinstance(commit.message, bytes):
339
352
            mapping_properties = set(
340
353
                [u'author', u'author-timezone', u'author-timezone-neg-utc',
341
354
                 u'commit-timezone-neg-utc', u'git-implicit-encoding',
342
 
                 u'git-gpg-signature', u'git-gpg-signature-b64',
343
 
                 u'git-explicit-encoding',
 
355
                 u'git-gpg-signature', u'git-explicit-encoding',
344
356
                 u'author-timestamp', u'file-modes'])
345
357
            for k, v in rev.properties.items():
346
358
                if k not in mapping_properties:
422
434
        if commit._commit_timezone_neg_utc:
423
435
            rev.properties[u'commit-timezone-neg-utc'] = ""
424
436
        if commit.gpgsig:
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)
 
437
            rev.properties[u'git-gpg-signature'] = commit.gpgsig.decode(
 
438
                'utf-8', 'surrogateescape')
431
439
        if commit.mergetag:
432
440
            for i, tag in enumerate(commit.mergetag):
433
441
                rev.properties[u'git-mergetag-%d' % i] = tag.as_raw_string()
574
582
    from dulwich.objects import Blob
575
583
    blob = Blob()
576
584
    if isinstance(symlink_target, str):
577
 
        symlink_target = symlink_target.encode('utf-8')
 
585
        symlink_target = encode_git_path(symlink_target)
578
586
    blob.data = symlink_target
579
587
    return blob
580
588