format-patch --notes: show notes after three-dashes
authorJunio C Hamano <gitster@pobox.com>
Thu, 18 Oct 2012 04:27:22 +0000 (21:27 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Oct 2012 05:42:40 +0000 (22:42 -0700)
When inserting the note after the commit log message to format-patch
output, add three dashes before the note.  Record the fact that we
did so in the rev_info and omit showing duplicated three dashes in
the usual codepath that is used when notes are not being shown.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
log-tree.c
revision.h
t/t4014-format-patch.sh

index 4390b117e3270f2bc416b5e133466edb72d0376c..712a22b19b11394067cb2b59a77a78fb6c870464 100644 (file)
@@ -677,8 +677,13 @@ void show_log(struct rev_info *opt)
                append_signoff(&msgbuf, opt->add_signoff);
 
        if ((ctx.fmt != CMIT_FMT_USERFORMAT) &&
-           ctx.notes_message && *ctx.notes_message)
+           ctx.notes_message && *ctx.notes_message) {
+               if (ctx.fmt == CMIT_FMT_EMAIL) {
+                       strbuf_addstr(&msgbuf, "---\n");
+                       opt->shown_dashes = 1;
+               }
                strbuf_addstr(&msgbuf, ctx.notes_message);
+       }
 
        if (opt->show_log_size) {
                printf("log size %i\n", (int)msgbuf.len);
@@ -710,6 +715,7 @@ void show_log(struct rev_info *opt)
 
 int log_tree_diff_flush(struct rev_info *opt)
 {
+       opt->shown_dashes = 0;
        diffcore_std(&opt->diffopt);
 
        if (diff_queue_is_empty()) {
@@ -737,10 +743,11 @@ int log_tree_diff_flush(struct rev_info *opt)
                                        opt->diffopt.output_prefix_data);
                                fwrite(msg->buf, msg->len, 1, stdout);
                        }
-                       if ((pch & opt->diffopt.output_format) == pch) {
-                               printf("---");
+                       if (!opt->shown_dashes) {
+                               if ((pch & opt->diffopt.output_format) == pch)
+                                       printf("---");
+                               putchar('\n');
                        }
-                       putchar('\n');
                }
        }
        diff_flush(&opt->diffopt);
index a95bd0b3f3026068046d469a74d1a2d85e50e314..059bfff812da8033681aa11c5a9ca9085881747e 100644 (file)
@@ -111,6 +111,7 @@ struct rev_info {
 
        /* Format info */
        unsigned int    shown_one:1,
+                       shown_dashes:1,
                        show_merge:1,
                        show_notes:1,
                        show_notes_given:1,
index bea63814e6a58e930aa46e6728cc3442fc4ea4f4..9750ba69962a2d5adf393882402480b9a94091c8 100755 (executable)
@@ -623,9 +623,12 @@ test_expect_success 'format-patch --signoff' '
 test_expect_success 'format-patch --notes --signoff' '
        git notes --ref test add -m "test message" HEAD &&
        git format-patch -1 --signoff --stdout --notes=test >out &&
-       # Notes message must come after S-o-b
+       # Three dashes must come after S-o-b
        ! sed "/^Signed-off-by: /q" out | grep "test message" &&
-       sed "1,/^Signed-off-by: /d" out | grep "test message"
+       sed "1,/^Signed-off-by: /d" out | grep "test message" &&
+       # Notes message must come after three dashes
+       ! sed "/^---$/q" out | grep "test message" &&
+       sed "1,/^---$/d" out | grep "test message"
 '
 
 echo "fatal: --name-only does not make sense" > expect.name-only