summaryrefslogtreecommitdiff
path: root/add-patch.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2020-11-11 12:28:16 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-11-11 17:07:52 (GMT)
commitdecc9ee4eaf2c33c28e2958439d276904a2ce279 (patch)
tree3a898371134bfb5cdd82e047c47cfc0815be3c9d /add-patch.c
parentcb581b16ef947a00f8e83f17c9fbe5b5aeed1d65 (diff)
downloadgit-decc9ee4eaf2c33c28e2958439d276904a2ce279.zip
git-decc9ee4eaf2c33c28e2958439d276904a2ce279.tar.gz
git-decc9ee4eaf2c33c28e2958439d276904a2ce279.tar.bz2
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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'add-patch.c')
-rw-r--r--add-patch.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/add-patch.c b/add-patch.c
index bd94bd3..55bd9d4 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -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)