Skip to content

Commit 9f726e1

Browse files
Denton-Lgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3bdbdfb commit 9f726e1

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

range-diff.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ static int read_patches(const char *range, struct string_list *list)
144144
strbuf_addstr(&buf, line);
145145
strbuf_addstr(&buf, "\n\n");
146146
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);
147153
} else if (starts_with(line, " ")) {
148154
p = line + len - 2;
149155
while (isspace(*p) && p >= line)

t/t3206-range-diff.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,10 @@ test_expect_success 'range-diff compares notes by default' '
516516
2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
517517
3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
518518
4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
519-
@@ Metadata
519+
@@ Commit message
520520
Z
521-
Z ## Commit message ##
522-
Z s/12/B/
521+
Z
522+
Z ## Notes ##
523523
- topic note
524524
+ unmodified note
525525
Z
@@ -543,17 +543,17 @@ test_expect_success 'format-patch --range-diff compares notes by default' '
543543
grep "= 3: .* s/11/B" 0000-* &&
544544
grep "! 4: .* s/12/B" 0000-* &&
545545
sed s/Z/\ /g >expect <<-EOF &&
546-
@@ Metadata
546+
@@ Commit message
547547
Z
548-
Z ## Commit message ##
549-
Z s/12/B/
548+
Z
549+
Z ## Notes ##
550550
- topic note
551551
+ unmodified note
552552
Z
553553
Z ## file ##
554554
Z@@ file: A
555555
EOF
556-
sed "/@@ Metadata/,/@@ file: A/!d" 0000-* >actual &&
556+
sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
557557
test_cmp expect actual
558558
'
559559

0 commit comments

Comments
 (0)