range-diff: output `## Notes ##` header
When notes were included in the output of range-diff, they were just mashed together with the rest of the commit message. As a result, users wouldn't be able to clearly distinguish where the commit message ended and where the notes started. Output a `## Notes ##` header when notes are detected so that notes can be compared more clearly. Note that we handle case of `Notes (<ref>): -> ## Notes (<ref>) ##` with this code as well. We can't test this in this patch, however, since there is currently no way to pass along different notes refs to `git log`. This will be fixed in a future patch. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Denton Liu committed
Nov 20, 2019 at 13:18 UTC
9f726e1b879f6cc191cf18e0b81dbea45eaee60d
2 files changed
+13
-7
range-diff.c
+6
@@ -144,6 +144,12 @@ static int read_patches(const char *range, struct string_list *list)
144
strbuf_addstr(&buf, line);
145
strbuf_addstr(&buf, "\n\n");
146
strbuf_addstr(&buf, " ## Commit message ##\n");
147
+ } else if (starts_with(line, "Notes") &&
148
+ line[strlen(line) - 1] == ':') {
149
+ strbuf_addstr(&buf, "\n\n");
150
+ /* strip the trailing colon */
151
+ strbuf_addf(&buf, " ## %.*s ##\n",
152
+ (int)(strlen(line) - 1), line);
153
} else if (starts_with(line, " ")) {
154
p = line + len - 2;
155
while (isspace(*p) && p >= line)
t/t3206-range-diff.sh
+7
-7
@@ -516,10 +516,10 @@ test_expect_success 'range-diff compares notes by default' '
516
2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
517
3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
518
4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
519
- @@ Metadata
519
+ @@ Commit message
520
Z
521
- Z ## Commit message ##
522
- Z s/12/B/
521
+ Z
522
+ Z ## Notes ##
523
- topic note
524
+ unmodified note
525
Z
@@ -543,17 +543,17 @@ test_expect_success 'format-patch --range-diff compares notes by default' '
543
grep "= 3: .* s/11/B" 0000-* &&
544
grep "! 4: .* s/12/B" 0000-* &&
545
sed s/Z/\ /g >expect <<-EOF &&
546
- @@ Metadata
546
+ @@ Commit message
547
Z
548
- Z ## Commit message ##
549
- Z s/12/B/
548
+ Z
549
+ Z ## Notes ##
550
- topic note
551
+ unmodified note
552
Z
553
Z ## file ##
554
Z@@ file: A
555
EOF
556
- sed "/@@ Metadata/,/@@ file: A/!d" 0000-* >actual &&
556
+ sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
557
test_cmp expect actual
558
'
559