Skip to content

Commit decc9ee

Browse files
dschogitster
authored andcommitted
add -p (built-in): imitate xdl_format_hunk_hdr() generating hunk headers
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cb581b1 commit decc9ee

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

add-patch.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,14 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk,
661661
else
662662
new_offset += delta;
663663

664-
strbuf_addf(out, "@@ -%lu,%lu +%lu,%lu @@",
665-
old_offset, header->old_count,
666-
new_offset, header->new_count);
664+
strbuf_addf(out, "@@ -%lu", old_offset);
665+
if (header->old_count != 1)
666+
strbuf_addf(out, ",%lu", header->old_count);
667+
strbuf_addf(out, " +%lu", new_offset);
668+
if (header->new_count != 1)
669+
strbuf_addf(out, ",%lu", header->new_count);
670+
strbuf_addstr(out, " @@");
671+
667672
if (len)
668673
strbuf_add(out, p, len);
669674
else if (colored)

0 commit comments

Comments
 (0)