Complete the search for viable hunks all the way down to 0 space context lines #435

This commit is contained in:
Paul Gauthier 2024-01-09 08:34:15 -08:00
parent e0e454fe82
commit 29a578c621

View file

@ -262,6 +262,9 @@ def normalize_hunk(hunk):
def directly_apply_hunk(content, hunk):
before, after = hunk_to_before_after(hunk)
if not before:
return
before_lines, _ = hunk_to_before_after(hunk, lines=True)
before_lines = "".join([line.strip() for line in before_lines])
@ -283,7 +286,8 @@ def apply_partial_hunk(content, preceding_context, changes, following_context):
use_all = len_prec + len_foll
for drop in range(use_all):
# if there is a - in the hunk, we can go all the way to `use=0`
for drop in range(use_all + 1):
use = use_all - drop
for use_prec in range(len_prec, -1, -1):