Skip to content

Commit 8506588

Browse files
committed
Merge branch 'jc/maint-apply-report-offset'
* jc/maint-apply-report-offset: apply -v: show offset count when patch did not apply exactly
2 parents af2b184 + 334f8cb commit 8506588

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

builtin/apply.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,7 +2437,8 @@ static void update_image(struct image *img,
24372437
}
24382438

24392439
static int apply_one_fragment(struct image *img, struct fragment *frag,
2440-
int inaccurate_eof, unsigned ws_rule)
2440+
int inaccurate_eof, unsigned ws_rule,
2441+
int nth_fragment)
24412442
{
24422443
int match_beginning, match_end;
24432444
const char *patch = frag->patch;
@@ -2643,6 +2644,15 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
26432644
apply = 0;
26442645
}
26452646

2647+
if (apply_verbosely && applied_pos != pos) {
2648+
int offset = applied_pos - pos;
2649+
if (apply_in_reverse)
2650+
offset = 0 - offset;
2651+
fprintf(stderr,
2652+
"Hunk #%d succeeded at %d (offset %d lines).\n",
2653+
nth_fragment, applied_pos + 1, offset);
2654+
}
2655+
26462656
/*
26472657
* Warn if it was necessary to reduce the number
26482658
* of context lines.
@@ -2790,12 +2800,14 @@ static int apply_fragments(struct image *img, struct patch *patch)
27902800
const char *name = patch->old_name ? patch->old_name : patch->new_name;
27912801
unsigned ws_rule = patch->ws_rule;
27922802
unsigned inaccurate_eof = patch->inaccurate_eof;
2803+
int nth = 0;
27932804

27942805
if (patch->is_binary)
27952806
return apply_binary(img, patch);
27962807

27972808
while (frag) {
2798-
if (apply_one_fragment(img, frag, inaccurate_eof, ws_rule)) {
2809+
nth++;
2810+
if (apply_one_fragment(img, frag, inaccurate_eof, ws_rule, nth)) {
27992811
error("patch failed: %s:%ld", name, frag->oldpos);
28002812
if (!apply_with_reject)
28012813
return -1;

0 commit comments

Comments
 (0)