/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

Support non-utf-8 characters in Git repositories by surrogate-escaping them.

Merged from https://code.launchpad.net/~jelmer/brz/git-surrogateencodes/+merge/386513

Show diffs side-by-side

added added

removed removed

Lines of Context:
135
135
 
136
136
def decode_git_path(path):
137
137
    """Take a git path and decode it."""
138
 
    return path.decode('utf-8')
 
138
    try:
 
139
        return path.decode('utf-8')
 
140
    except UnicodeDecodeError:
 
141
        if PY3:
 
142
            return path.decode('utf-8', 'surrogateescape')
 
143
        raise
139
144
 
140
145
 
141
146
def encode_git_path(path):
142
147
    """Take a regular path and encode it for git."""
143
 
    return path.encode('utf-8')
 
148
    try:
 
149
        return path.encode('utf-8')
 
150
    except UnicodeEncodeError:
 
151
        if PY3:
 
152
            return path.encode('utf-8', 'surrogateescape')
 
153
        raise
144
154
 
145
155
 
146
156
def warn_escaped(commit, num_escaped):
344
354
            commit.author_timezone = commit.commit_timezone
345
355
        if u'git-gpg-signature' in rev.properties:
346
356
            commit.gpgsig = rev.properties[u'git-gpg-signature'].encode(
347
 
                'utf-8', 'surrogateencode')
 
357
                'utf-8', 'surrogateescape')
348
358
        commit.message = self._encode_commit_message(rev, rev.message,
349
359
                                                     encoding)
350
360
        if not isinstance(commit.message, bytes):