]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Fix "log" family not to be too agressive about showing notes
authorJunio C Hamano <gitster@pobox.com>
Wed, 20 Jan 2010 21:59:36 +0000 (13:59 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Jan 2010 03:57:02 +0000 (19:57 -0800)
Giving "Notes" information in the default output format of "log" and
"show" is a sensible progress (the user has asked for it by having the
notes), but for some commands (e.g. "format-patch") spewing notes into the
formatted commit log message without being asked is too aggressive.

Enable notes output only for "log", "show", "whatchanged" by default and
only when the user didn't ask any specific --pretty/--format from the
command line; users can explicitly override this default with --show-notes
and --no-notes option.

Parts of tests are taken from Jeff King's fix.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/pretty-options.txt
builtin-log.c
commit.h
log-tree.c
pretty.c
revision.c
revision.h
t/t3301-notes.sh

index bff94991b68aaca5a81eae4e6681f3431aa6b9ac..140120092083558b418decca69088b336d134153 100644 (file)
@@ -28,3 +28,11 @@ people using 80-column terminals.
        command to re-code the commit log message in the encoding
        preferred by the user.  For non plumbing commands this
        defaults to UTF-8.
+
+--no-notes::
+--show-notes::
+       Show the notes (see linkgit:git-notes[1]) that annotate the
+       commit, when showing the commit log message.  This is the default
+       for `git log`, `git show` and `git whatchanged` commands when
+       there is no `--pretty` nor `--format` option is given on the
+       command line.
index 1766349550f5b4204e77f6f6eeca486cee322ca1..2cb292fa727222487b5fed7f6f4db2bcc4237f49 100644 (file)
@@ -58,6 +58,9 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
                usage(builtin_log_usage);
        argc = setup_revisions(argc, argv, rev, "HEAD");
 
+       if (!rev->show_notes_given && !rev->pretty_given)
+               rev->show_notes = 1;
+
        if (rev->diffopt.pickaxe || rev->diffopt.filter)
                rev->always_show_header = 0;
        if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) {
index e5332efcfc9449e0f3af4d6c49be63adfeb138b1..2c0742b721fe1d4d78a7a63ed1c2ee1cf9c96ab8 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -70,6 +70,7 @@ struct pretty_print_context
        const char *after_subject;
        enum date_mode date_mode;
        int need_8bit_cte;
+       int show_notes;
        struct reflog_walk_info *reflog_info;
 };
 
index 0fdf159f8098532e3ed77251d36e163b695310ba..27afcf697238a48c01dd49996f5263cd72a52eac 100644 (file)
@@ -284,6 +284,7 @@ void show_log(struct rev_info *opt)
        struct pretty_print_context ctx = {0};
 
        opt->loginfo = NULL;
+       ctx.show_notes = opt->show_notes;
        if (!opt->verbose_header) {
                graph_show_commit(opt->graph);
 
index 8f5bd1ab7f119715564fb13cb74de3937d1a3774..b2ee7fe9de2830dbc276b49d54a18d1130b751a2 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -1094,7 +1094,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
        if (fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
                strbuf_addch(sb, '\n');
 
-       if (fmt != CMIT_FMT_ONELINE)
+       if (context->show_notes)
                get_commit_notes(commit, sb, encoding,
                                 NOTES_SHOW_HEADER | NOTES_INDENT);
 
index a8a3c3a4bdf5bd9287cb820330e73e8c28b88564..0de78fbad6008b72aba946df0dfd03d5183f42bf 100644 (file)
@@ -1161,10 +1161,18 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->verbose_header = 1;
        } else if (!strcmp(arg, "--pretty")) {
                revs->verbose_header = 1;
+               revs->pretty_given = 1;
                get_commit_format(arg+8, revs);
        } else if (!prefixcmp(arg, "--pretty=") || !prefixcmp(arg, "--format=")) {
                revs->verbose_header = 1;
+               revs->pretty_given = 1;
                get_commit_format(arg+9, revs);
+       } else if (!strcmp(arg, "--show-notes")) {
+               revs->show_notes = 1;
+               revs->show_notes_given = 1;
+       } else if (!strcmp(arg, "--no-notes")) {
+               revs->show_notes = 0;
+               revs->show_notes_given = 1;
        } else if (!strcmp(arg, "--oneline")) {
                revs->verbose_header = 1;
                get_commit_format("oneline", revs);
index d368003159738570220c0e4713efd91f83303339..a14deefc252bd641fba5e16f7859b4a985a72578 100644 (file)
@@ -80,6 +80,9 @@ struct rev_info {
        /* Format info */
        unsigned int    shown_one:1,
                        show_merge:1,
+                       show_notes:1,
+                       show_notes_given:1,
+                       pretty_given:1,
                        abbrev_commit:1,
                        use_terminator:1,
                        missing_newline:1,
index 1e34f4836f4840b1cd30fdc635e56e50e4c669df..977d6536515e4128a2130a8b5fc911e2c0aafe40 100755 (executable)
@@ -147,4 +147,61 @@ test_expect_success 'show -m and -F notes' '
        test_cmp expect-m-and-F output
 '
 
+cat >expect << EOF
+commit 15023535574ded8b1a89052b32673f84cf9582b8
+tree e070e3af51011e47b183c33adf9736736a525709
+parent 1584215f1d29c65e99c6c6848626553fdd07fd75
+author A U Thor <author@example.com> 1112912173 -0700
+committer C O Mitter <committer@example.com> 1112912173 -0700
+
+    4th
+EOF
+test_expect_success 'git log --pretty=raw does not show notes' '
+       git log -1 --pretty=raw >output &&
+       test_cmp expect output
+'
+
+cat >>expect <<EOF
+
+Notes:
+    spam
+$whitespace
+    xyzzy
+$whitespace
+    foo
+    bar
+    baz
+EOF
+test_expect_success 'git log --show-notes' '
+       git log -1 --pretty=raw --show-notes >output &&
+       test_cmp expect output
+'
+
+test_expect_success 'git log --no-notes' '
+       git log -1 --no-notes >output &&
+       ! grep spam output
+'
+
+test_expect_success 'git format-patch does not show notes' '
+       git format-patch -1 --stdout >output &&
+       ! grep spam output
+'
+
+test_expect_success 'git format-patch --show-notes does show notes' '
+       git format-patch --show-notes -1 --stdout >output &&
+       grep spam output
+'
+
+for pretty in "" raw short medium full fuller format:%s
+do
+       case "$pretty" in
+       "") p= not= negate="" ;;
+       ?*) p="--pretty=$pretty" not=" not" negate="!" ;;
+       esac
+       test_expect_success "git show $pretty does$not show notes" '
+               git show $p >output &&
+               eval "$negate grep spam output"
+       '
+done
+
 test_done