Skip to content

Commit 67ba272

Browse files
dschoGit for Windows Build Agent
authored andcommitted
fixup??? built-in add -p: adjust hunk headers as needed
... to accommodate for the bug fix in pw/add-p-recount. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 589a072 commit 67ba272

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

add-patch.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk,
582582
*/
583583
const char *p;
584584
size_t len;
585+
unsigned long old_offset = header->old_offset;
586+
unsigned long new_offset = header->new_offset;
585587

586588
if (!colored) {
587589
p = s->plain.buf + header->extra_start;
@@ -593,10 +595,14 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk,
593595
- header->colored_extra_start;
594596
}
595597

598+
if (s->mode->is_reverse)
599+
old_offset -= delta;
600+
else
601+
new_offset += delta;
602+
596603
strbuf_addf(out, "@@ -%lu,%lu +%lu,%lu @@",
597-
header->old_offset, header->old_count,
598-
(unsigned long)(header->new_offset + delta),
599-
header->new_count);
604+
old_offset, header->old_count,
605+
new_offset, header->new_count);
600606
if (len)
601607
strbuf_add(out, p, len);
602608
else if (colored)

0 commit comments

Comments
 (0)