mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 12:50:38 +08:00
Merge pull request #170 from Codium-ai/tr/edge_case_for_hunks
Handling edge case for hunks in git patch processing
This commit is contained in:
@ -41,7 +41,11 @@ def extend_patch(original_file_str, patch_str, num_lines) -> str:
|
|||||||
extended_patch_lines.extend(
|
extended_patch_lines.extend(
|
||||||
original_lines[start1 + size1 - 1:start1 + size1 - 1 + num_lines])
|
original_lines[start1 + size1 - 1:start1 + size1 - 1 + num_lines])
|
||||||
|
|
||||||
|
try:
|
||||||
start1, size1, start2, size2 = map(int, match.groups()[:4])
|
start1, size1, start2, size2 = map(int, match.groups()[:4])
|
||||||
|
except: # '@@ -0,0 +1 @@' case
|
||||||
|
start1, size1, size2 = map(int, match.groups()[:3])
|
||||||
|
start2 = 0
|
||||||
section_header = match.groups()[4]
|
section_header = match.groups()[4]
|
||||||
extended_start1 = max(1, start1 - num_lines)
|
extended_start1 = max(1, start1 - num_lines)
|
||||||
extended_size1 = size1 + (start1 - extended_start1) + num_lines
|
extended_size1 = size1 + (start1 - extended_start1) + num_lines
|
||||||
@ -198,7 +202,12 @@ def convert_to_hunks_with_lines_numbers(patch: str, file) -> str:
|
|||||||
patch_with_lines_str += f"{line_old}\n"
|
patch_with_lines_str += f"{line_old}\n"
|
||||||
new_content_lines = []
|
new_content_lines = []
|
||||||
old_content_lines = []
|
old_content_lines = []
|
||||||
|
try:
|
||||||
start1, size1, start2, size2 = map(int, match.groups()[:4])
|
start1, size1, start2, size2 = map(int, match.groups()[:4])
|
||||||
|
except: # '@@ -0,0 +1 @@' case
|
||||||
|
start1, size1, size2 = map(int, match.groups()[:3])
|
||||||
|
start2 = 0
|
||||||
|
|
||||||
elif line.startswith('+'):
|
elif line.startswith('+'):
|
||||||
new_content_lines.append(line)
|
new_content_lines.append(line)
|
||||||
elif line.startswith('-'):
|
elif line.startswith('-'):
|
||||||
|
Reference in New Issue
Block a user