summaryrefslogtreecommitdiff
path: root/git/diff.py
diff options
context:
space:
mode:
Diffstat (limited to 'git/diff.py')
-rw-r--r--git/diff.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/git/diff.py b/git/diff.py
index 44a65017..aeaa67d5 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -15,12 +15,23 @@ from git.compat import (
PY3
)
-
__all__ = ('Diffable', 'DiffIndex', 'Diff', 'NULL_TREE')
# Special object to compare against the empty tree in diffs
NULL_TREE = object()
+_octal_byte_re = re.compile(b'\\\\([0-9]{3})')
+
+
+def _octal_repl(matchobj):
+ value = matchobj.group(1)
+ value = int(value, 8)
+ if PY3:
+ value = bytes(bytearray((value,)))
+ else:
+ value = chr(value)
+ return value
+
def decode_path(path, has_ab_prefix=True):
if path == b'/dev/null':
@@ -32,6 +43,8 @@ def decode_path(path, has_ab_prefix=True):
.replace(b'\\"', b'"')
.replace(b'\\\\', b'\\'))
+ path = _octal_byte_re.sub(_octal_repl, path)
+
if has_ab_prefix:
assert path.startswith(b'a/') or path.startswith(b'b/')
path = path[2:]
@@ -337,7 +350,7 @@ class Diff(object):
:note: This property is deprecated, please use ``renamed_file`` instead.
"""
return self.renamed_file
-
+
@property
def renamed_file(self):
""":returns: True if the blob of our diff has been renamed
@@ -391,15 +404,15 @@ class Diff(object):
a_mode = old_mode or deleted_file_mode or (a_path and (b_mode or new_mode or new_file_mode))
b_mode = b_mode or new_mode or new_file_mode or (b_path and a_mode)
index.append(Diff(repo,
- a_path and a_path.decode(defenc),
- b_path and b_path.decode(defenc),
+ a_path and a_path.decode(defenc, 'replace'),
+ b_path and b_path.decode(defenc, 'replace'),
a_blob_id and a_blob_id.decode(defenc),
b_blob_id and b_blob_id.decode(defenc),
a_mode and a_mode.decode(defenc),
b_mode and b_mode.decode(defenc),
new_file, deleted_file,
- rename_from and rename_from.decode(defenc),
- rename_to and rename_to.decode(defenc),
+ rename_from and rename_from.decode(defenc, 'replace'),
+ rename_to and rename_to.decode(defenc, 'replace'),
None))
previous_header = header