/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-02-18 01:57:45 UTC
  • mto: This revision was merged to the branch mainline in revision 7493.
  • Revision ID: jelmer@jelmer.uk-20200218015745-q2ss9tsk74h4nh61
drop use of future.

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)
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
                'ascii')
343
328
        commit.message = self._encode_commit_message(rev, rev.message,
344
329
                                                     encoding)
345
330
        if not isinstance(commit.message, bytes):
435
420
            rev.properties[u'commit-timezone-neg-utc'] = ""
436
421
        if commit.gpgsig:
437
422
            rev.properties[u'git-gpg-signature'] = commit.gpgsig.decode(
438
 
                'utf-8', 'surrogateescape')
 
423
                'ascii')
439
424
        if commit.mergetag:
440
425
            for i, tag in enumerate(commit.mergetag):
441
426
                rev.properties[u'git-mergetag-%d' % i] = tag.as_raw_string()
582
567
    from dulwich.objects import Blob
583
568
    blob = Blob()
584
569
    if isinstance(symlink_target, str):
585
 
        symlink_target = encode_git_path(symlink_target)
 
570
        symlink_target = symlink_target.encode('utf-8')
586
571
    blob.data = symlink_target
587
572
    return blob
588
573