Skip to content

Commit 67bc740

Browse files
committed
Merge branch 'jc/maint-limit-note-output'
* jc/maint-limit-note-output: Fix "log --oneline" not to show notes Fix "log" family not to be too agressive about showing notes
2 parents f986eec + 7dccadf commit 67bc740

File tree

8 files changed

+85
-1
lines changed

8 files changed

+85
-1
lines changed

Documentation/pretty-options.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ people using 80-column terminals.
2828
command to re-code the commit log message in the encoding
2929
preferred by the user. For non plumbing commands this
3030
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`, `--format` nor `--oneline` option is
38+
given on the command line.

builtin-log.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
5858
usage(builtin_log_usage);
5959
argc = setup_revisions(argc, argv, rev, "HEAD");
6060

61+
if (!rev->show_notes_given && !rev->pretty_given)
62+
rev->show_notes = 1;
63+
6164
if (rev->diffopt.pickaxe || rev->diffopt.filter)
6265
rev->always_show_header = 0;
6366
if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) {

commit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct pretty_print_context
7070
const char *after_subject;
7171
enum date_mode date_mode;
7272
int need_8bit_cte;
73+
int show_notes;
7374
struct reflog_walk_info *reflog_info;
7475
};
7576

log-tree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ void show_log(struct rev_info *opt)
284284
struct pretty_print_context ctx = {0};
285285

286286
opt->loginfo = NULL;
287+
ctx.show_notes = opt->show_notes;
287288
if (!opt->verbose_header) {
288289
graph_show_commit(opt->graph);
289290

pretty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
10941094
if (fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
10951095
strbuf_addch(sb, '\n');
10961096

1097-
if (fmt != CMIT_FMT_ONELINE)
1097+
if (context->show_notes)
10981098
get_commit_notes(commit, sb, encoding,
10991099
NOTES_SHOW_HEADER | NOTES_INDENT);
11001100

revision.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,13 +1161,22 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
11611161
revs->verbose_header = 1;
11621162
} else if (!strcmp(arg, "--pretty")) {
11631163
revs->verbose_header = 1;
1164+
revs->pretty_given = 1;
11641165
get_commit_format(arg+8, revs);
11651166
} else if (!prefixcmp(arg, "--pretty=") || !prefixcmp(arg, "--format=")) {
11661167
revs->verbose_header = 1;
1168+
revs->pretty_given = 1;
11671169
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;
11681176
} else if (!strcmp(arg, "--oneline")) {
11691177
revs->verbose_header = 1;
11701178
get_commit_format("oneline", revs);
1179+
revs->pretty_given = 1;
11711180
revs->abbrev_commit = 1;
11721181
} else if (!strcmp(arg, "--graph")) {
11731182
revs->topo_order = 1;

revision.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ struct rev_info {
8080
/* Format info */
8181
unsigned int shown_one:1,
8282
show_merge:1,
83+
show_notes:1,
84+
show_notes_given:1,
85+
pretty_given:1,
8386
abbrev_commit:1,
8487
use_terminator:1,
8588
missing_newline:1,

t/t3301-notes.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,63 @@ test_expect_success 'show -m and -F notes' '
147147
test_cmp expect-m-and-F output
148148
'
149149

150+
cat >expect << EOF
151+
commit 15023535574ded8b1a89052b32673f84cf9582b8
152+
tree e070e3af51011e47b183c33adf9736736a525709
153+
parent 1584215f1d29c65e99c6c6848626553fdd07fd75
154+
author A U Thor <[email protected]> 1112912173 -0700
155+
committer C O Mitter <[email protected]> 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 \
196+
"" --pretty --pretty=raw --pretty=short --pretty=medium \
197+
--pretty=full --pretty=fuller --pretty=format:%s --oneline
198+
do
199+
case "$pretty" in
200+
"") p= not= negate="" ;;
201+
?*) p="$pretty" not=" not" negate="!" ;;
202+
esac
203+
test_expect_success "git show $pretty does$not show notes" '
204+
git show $p >output &&
205+
eval "$negate grep spam output"
206+
'
207+
done
208+
150209
test_done

0 commit comments

Comments
 (0)