summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2021-01-05 15:53:32 +0100
committerSebastian Thiel <sebastian.thiel@icloud.com>2021-01-06 01:13:51 +0800
commit69b75e167408d0dfa3ff8a00c185b3a0bc965b58 (patch)
tree5efda54acd36751476d268509310cb915e0a2c8e
parent82189398e3b9e8f5d8f97074784d77d7c27086ae (diff)
downloadgitpython-69b75e167408d0dfa3ff8a00c185b3a0bc965b58.tar.gz
Fix handle_diff_line for -z option.
-rw-r--r--git/diff.py98
1 files changed, 49 insertions, 49 deletions
diff --git a/git/diff.py b/git/diff.py
index cd7cc23c..a9dc4b57 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -479,55 +479,55 @@ class Diff(object):
index = DiffIndex()
- def handle_diff_line(line):
- line = line.decode(defenc)
- if not line.startswith(":"):
- return
-
- meta, _, path = line[1:].partition('\x00')
- old_mode, new_mode, a_blob_id, b_blob_id, _change_type = meta.split(None, 4)
- # Change type can be R100
- # R: status letter
- # 100: score (in case of copy and rename)
- change_type = _change_type[0]
- score_str = ''.join(_change_type[1:])
- score = int(score_str) if score_str.isdigit() else None
- path = path.strip()
- a_path = path.encode(defenc)
- b_path = path.encode(defenc)
- deleted_file = False
- new_file = False
- copied_file = False
- rename_from = None
- rename_to = None
-
- # NOTE: We cannot conclude from the existence of a blob to change type
- # as diffs with the working do not have blobs yet
- if change_type == 'D':
- b_blob_id = None
- deleted_file = True
- elif change_type == 'A':
- a_blob_id = None
- new_file = True
- elif change_type == 'C':
- copied_file = True
- a_path, b_path = path.split('\x00', 1)
- a_path = a_path.encode(defenc)
- b_path = b_path.encode(defenc)
- elif change_type == 'R':
- a_path, b_path = path.split('\x00', 1)
- a_path = a_path.encode(defenc)
- b_path = b_path.encode(defenc)
- rename_from, rename_to = a_path, b_path
- elif change_type == 'T':
- # Nothing to do
- pass
- # END add/remove handling
-
- diff = Diff(repo, a_path, b_path, a_blob_id, b_blob_id, old_mode, new_mode,
- new_file, deleted_file, copied_file, rename_from, rename_to,
- '', change_type, score)
- index.append(diff)
+ def handle_diff_line(lines):
+ lines = lines.decode(defenc)
+
+ for line in lines.split(':')[1:]:
+ meta, _, path = line.partition('\x00')
+ path = path.rstrip('\x00')
+ old_mode, new_mode, a_blob_id, b_blob_id, _change_type = meta.split(None, 4)
+ # Change type can be R100
+ # R: status letter
+ # 100: score (in case of copy and rename)
+ change_type = _change_type[0]
+ score_str = ''.join(_change_type[1:])
+ score = int(score_str) if score_str.isdigit() else None
+ path = path.strip()
+ a_path = path.encode(defenc)
+ b_path = path.encode(defenc)
+ deleted_file = False
+ new_file = False
+ copied_file = False
+ rename_from = None
+ rename_to = None
+
+ # NOTE: We cannot conclude from the existence of a blob to change type
+ # as diffs with the working do not have blobs yet
+ if change_type == 'D':
+ b_blob_id = None
+ deleted_file = True
+ elif change_type == 'A':
+ a_blob_id = None
+ new_file = True
+ elif change_type == 'C':
+ copied_file = True
+ a_path, b_path = path.split('\x00', 1)
+ a_path = a_path.encode(defenc)
+ b_path = b_path.encode(defenc)
+ elif change_type == 'R':
+ a_path, b_path = path.split('\x00', 1)
+ a_path = a_path.encode(defenc)
+ b_path = b_path.encode(defenc)
+ rename_from, rename_to = a_path, b_path
+ elif change_type == 'T':
+ # Nothing to do
+ pass
+ # END add/remove handling
+
+ diff = Diff(repo, a_path, b_path, a_blob_id, b_blob_id, old_mode, new_mode,
+ new_file, deleted_file, copied_file, rename_from, rename_to,
+ '', change_type, score)
+ index.append(diff)
handle_process_output(proc, handle_diff_line, None, finalize_process, decode_streams=False)