Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Get correcly rename change_type.
Also store the rename score
  • Loading branch information
LeResKP committed May 18, 2018
commit 9199faa46218cdba91d96fdd9c5faa40da5a827a
20 changes: 14 additions & 6 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ class Diff(object):

__slots__ = ("a_blob", "b_blob", "a_mode", "b_mode", "a_rawpath", "b_rawpath",
"new_file", "deleted_file", "raw_rename_from", "raw_rename_to",
"diff", "change_type")
"diff", "change_type", "score")

def __init__(self, repo, a_rawpath, b_rawpath, a_blob_id, b_blob_id, a_mode,
b_mode, new_file, deleted_file, raw_rename_from,
raw_rename_to, diff, change_type):
raw_rename_to, diff, change_type, score):

self.a_mode = a_mode
self.b_mode = b_mode
Expand Down Expand Up @@ -291,6 +291,7 @@ def __init__(self, repo, a_rawpath, b_rawpath, a_blob_id, b_blob_id, a_mode,

self.diff = diff
self.change_type = change_type
self.score = score

def __eq__(self, other):
for name in self.__slots__:
Expand Down Expand Up @@ -445,7 +446,7 @@ def _index_from_patch_format(cls, repo, proc):
new_file, deleted_file,
rename_from,
rename_to,
None, None))
None, None, None))

previous_header = header
# end for each header we parse
Expand All @@ -470,7 +471,13 @@ def handle_diff_line(line):
return

meta, _, path = line[1:].partition('\t')
old_mode, new_mode, a_blob_id, b_blob_id, change_type = meta.split(None, 4)
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)
Expand All @@ -487,15 +494,16 @@ def handle_diff_line(line):
elif change_type == 'A':
a_blob_id = None
new_file = True
elif change_type[0] == 'R': # parses RXXX, where XXX is a confidence value
elif change_type == 'R':
a_path, b_path = path.split('\t', 1)
a_path = a_path.encode(defenc)
b_path = b_path.encode(defenc)
rename_from, rename_to = a_path, b_path
# 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, rename_from, rename_to, '', change_type)
new_file, deleted_file, rename_from, rename_to, '',
change_type, score)
index.append(diff)

handle_process_output(proc, handle_diff_line, None, finalize_process, decode_streams=False)
Expand Down
2 changes: 2 additions & 0 deletions git/test/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def test_diff_with_rename(self):
self.assertIsNotNone(diff.renamed)
self.assertEqual(diff.rename_from, 'this')
self.assertEqual(diff.rename_to, 'that')
self.assertEqual(diff.change_type, 'R')
self.assertEqual(diff.score, 100)
self.assertEqual(len(list(diffs.iter_change_type('R'))), 1)

def test_diff_of_modified_files_not_added_to_the_index(self):
Expand Down