Fix "log" family not to be too agressive about showing notes
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>
Junio C Hamano committed
Jan 20, 2010 at 13:59 UTC
66b2ed09c2f0f212c5cd5c095c1f1052ecbb9491
8 files changed
+82
-1
Documentation/pretty-options.txt
+8
@@ -28,3 +28,11 @@ people using 80-column terminals.
28
command to re-code the commit log message in the encoding
29
preferred by the user. For non plumbing commands this
30
defaults to UTF-8.
31
+
32
+--no-notes::
33
+--show-notes::
34
+ Show the notes (see linkgit:git-notes[1]) that annotate the
35
+ commit, when showing the commit log message. This is the default
36
+ for `git log`, `git show` and `git whatchanged` commands when
37
+ there is no `--pretty` nor `--format` option is given on the
38
+ command line.
builtin-log.c
+3
@@ -58,6 +58,9 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
58
usage(builtin_log_usage);
59
argc = setup_revisions(argc, argv, rev, "HEAD");
60
61
+ if (!rev->show_notes_given && !rev->pretty_given)
62
+ rev->show_notes = 1;
63
+
64
if (rev->diffopt.pickaxe || rev->diffopt.filter)
65
rev->always_show_header = 0;
66
if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) {
commit.h
+1
@@ -70,6 +70,7 @@ struct pretty_print_context
70
const char *after_subject;
71
enum date_mode date_mode;
72
int need_8bit_cte;
73
+ int show_notes;
74
struct reflog_walk_info *reflog_info;
75
};
76
log-tree.c
+1
@@ -284,6 +284,7 @@ void show_log(struct rev_info *opt)
284
struct pretty_print_context ctx = {0};
285
286
opt->loginfo = NULL;
287
+ ctx.show_notes = opt->show_notes;
288
if (!opt->verbose_header) {
289
graph_show_commit(opt->graph);
290
pretty.c
+1
-1
@@ -1094,7 +1094,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
1094
if (fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
1095
strbuf_addch(sb, '\n');
1096
1097
- if (fmt != CMIT_FMT_ONELINE)
1097
+ if (context->show_notes)
1098
get_commit_notes(commit, sb, encoding,
1099
NOTES_SHOW_HEADER | NOTES_INDENT);
1100
revision.c
+8
@@ -1161,10 +1161,18 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1161
revs->verbose_header = 1;
1162
} else if (!strcmp(arg, "--pretty")) {
1163
revs->verbose_header = 1;
1164
+ revs->pretty_given = 1;
1165
get_commit_format(arg+8, revs);
1166
} else if (!prefixcmp(arg, "--pretty=") || !prefixcmp(arg, "--format=")) {
1167
revs->verbose_header = 1;
1168
+ revs->pretty_given = 1;
1169
get_commit_format(arg+9, revs);
1170
+ } else if (!strcmp(arg, "--show-notes")) {
1171
+ revs->show_notes = 1;
1172
+ revs->show_notes_given = 1;
1173
+ } else if (!strcmp(arg, "--no-notes")) {
1174
+ revs->show_notes = 0;
1175
+ revs->show_notes_given = 1;
1176
} else if (!strcmp(arg, "--oneline")) {
1177
revs->verbose_header = 1;
1178
get_commit_format("oneline", revs);
revision.h
+3
@@ -80,6 +80,9 @@ struct rev_info {
80
/* Format info */
81
unsigned int shown_one:1,
82
show_merge:1,
83
+ show_notes:1,
84
+ show_notes_given:1,
85
+ pretty_given:1,
86
abbrev_commit:1,
87
use_terminator:1,
88
missing_newline:1,
t/t3301-notes.sh
+57
@@ -147,4 +147,61 @@ test_expect_success 'show -m and -F notes' '
147
test_cmp expect-m-and-F output
148
'
149
150
+cat >expect << EOF
151
+commit 15023535574ded8b1a89052b32673f84cf9582b8
152
+tree e070e3af51011e47b183c33adf9736736a525709
153
+parent 1584215f1d29c65e99c6c6848626553fdd07fd75
154
+author A U Thor <author@example.com> 1112912173 -0700
155
+committer C O Mitter <committer@example.com> 1112912173 -0700
156
+
157
+ 4th
158
+EOF
159
+test_expect_success 'git log --pretty=raw does not show notes' '
160
+ git log -1 --pretty=raw >output &&
161
+ test_cmp expect output
162
+'
163
+
164
+cat >>expect <<EOF
165
+
166
+Notes:
167
+ spam
168
+$whitespace
169
+ xyzzy
170
+$whitespace
171
+ foo
172
+ bar
173
+ baz
174
+EOF
175
+test_expect_success 'git log --show-notes' '
176
+ git log -1 --pretty=raw --show-notes >output &&
177
+ test_cmp expect output
178
+'
179
+
180
+test_expect_success 'git log --no-notes' '
181
+ git log -1 --no-notes >output &&
182
+ ! grep spam output
183
+'
184
+
185
+test_expect_success 'git format-patch does not show notes' '
186
+ git format-patch -1 --stdout >output &&
187
+ ! grep spam output
188
+'
189
+
190
+test_expect_success 'git format-patch --show-notes does show notes' '
191
+ git format-patch --show-notes -1 --stdout >output &&
192
+ grep spam output
193
+'
194
+
195
+for pretty in "" raw short medium full fuller format:%s
196
+do
197
+ case "$pretty" in
198
+ "") p= not= negate="" ;;
199
+ ?*) p="--pretty=$pretty" not=" not" negate="!" ;;
200
+ esac
201
+ test_expect_success "git show $pretty does$not show notes" '
202
+ git show $p >output &&
203
+ eval "$negate grep spam output"
204
+ '
205
+done
206
+
207
test_done