Compare commits

..

No commits in common. "8033e648ef2ae242ed897536431c4cfd41ba7bb7" and "6e5c3d7f07ad651202328aa41682938e01319bfd" have entirely different histories.

View File

@ -33,26 +33,18 @@ class LineShiftChecker:
return file_list return file_list
def __get_shifted_lines_in_file(self, file_info) -> 'Dict[str, str | None]': def __get_shifted_lines_in_file(self, file_info) -> 'Dict[str, str | None]':
process_output = subprocess_readlines(['git', 'diff', lines_in_source_file = self.__count_lines_in_source_file(file_info['src'])
process_output = subprocess_readlines(['git', 'diff', f'-U{lines_in_source_file}',
self.revision_since, self.revision_until, '--', self.revision_since, self.revision_until, '--',
file_info['src'], file_info['dst']]) file_info['src'], file_info['dst']])
shifted_lines = {}
src_line_index = 1
dst_line_index = 1
diff_started = False diff_started = False
shifted_lines = {}
for line in process_output: for line in process_output:
matches = re.search(LineShiftChecker.DIFF_BLOCK_REGEX, line) matches = re.search(LineShiftChecker.DIFF_BLOCK_REGEX, line)
if matches: if matches:
diff_block_src_start = int(matches.group(1)) old_start = int(matches.group(1))
diff_block_dst_start = int(matches.group(3)) new_start = int(matches.group(3))
# fill shifted lines between 2 diff blocks
for i in range(0, diff_block_src_start - src_line_index):
shifted_lines[f'{file_info["src"]}:{src_line_index+i}'] = f'{file_info["dst"]}:{dst_line_index+i}'
src_line_index = diff_block_src_start
dst_line_index = diff_block_dst_start
diff_started = True diff_started = True
continue continue
@ -60,19 +52,20 @@ class LineShiftChecker:
continue continue
if line.startswith(' '): if line.startswith(' '):
shifted_lines[f'{file_info["src"]}:{src_line_index}'] = f'{file_info["dst"]}:{dst_line_index}' shifted_lines[f'{file_info["src"]}:{old_start}'] = f'{file_info["dst"]}:{new_start}'
src_line_index += 1 old_start += 1
dst_line_index += 1 new_start += 1
elif line.startswith('+'): elif line.startswith('+'):
dst_line_index += 1 new_start += 1
elif line.startswith('-'): elif line.startswith('-'):
shifted_lines[f'{file_info["src"]}:{src_line_index}'] = None shifted_lines[f'{file_info["src"]}:{old_start}'] = None
src_line_index += 1 old_start += 1
# fill shifted lines until end of file if not diff_started:
lines_in_source_file = self.__count_lines_in_source_file(file_info['src']) # it was a pure rename, so no diff blocks were returned,
for i in range(0, lines_in_source_file - src_line_index + 1): # we just put the lines into the dict
shifted_lines[f'{file_info["src"]}:{src_line_index+i}'] = f'{file_info["dst"]}:{dst_line_index+i}' shifted_lines = {f'{file_info["src"]}:{i}': f'{file_info["dst"]}:{i}'
for i in range(0, lines_in_source_file)}
assert lines_in_source_file == len(shifted_lines) assert lines_in_source_file == len(shifted_lines)