Skip to content

Commit

Permalink
add -p (built-in): imitate xdl_format_hunk_hdr() generating hunk he…
Browse files Browse the repository at this point in the history
…aders

In libxdiff, imitating GNU diff, the hunk headers only show the line
count if it is different from 1. When splitting hunks, the Perl version
of `git add -p` already imitates this. Let's do the same in the built-in
version of said command.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
dscho authored and gitster committed Nov 11, 2020
1 parent cb581b1 commit decc9ee
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions add-patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,14 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk,
else
new_offset += delta;

strbuf_addf(out, "@@ -%lu,%lu +%lu,%lu @@",
old_offset, header->old_count,
new_offset, header->new_count);
strbuf_addf(out, "@@ -%lu", old_offset);
if (header->old_count != 1)
strbuf_addf(out, ",%lu", header->old_count);
strbuf_addf(out, " +%lu", new_offset);
if (header->new_count != 1)
strbuf_addf(out, ",%lu", header->new_count);
strbuf_addstr(out, " @@");

if (len)
strbuf_add(out, p, len);
else if (colored)
Expand Down

0 comments on commit decc9ee

Please sign in to comment.