@matheusbsbs / matheus-bagliano / commits / 7249e91287
Fork 0

revision.c: support --notes command-line option

We already have --show-notes, but it has a few shortcomings: 1. Using --show-notes=<ref> implies that we should also show the default notes. Which means you also need to use --no-standard-notes if you want to suppress them. 2. It is negated by --no-notes, which doesn't match. 3. It's too long to type. :) This patch introduces --notes, which behaves exactly like --show-notes, except that using "--notes=<ref>" does not imply showing the default notes. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 29, 2011 at 16:57 UTC 7249e91287443c02b2c7eed272a579dae44984ad
2 files changed +32 -5
revision.c
+10 -5
@@ -1367,17 +1367,22 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1367 revs->verbose_header = 1;
1368 revs->pretty_given = 1;
1369 get_commit_format(arg+9, revs);
1370 - } else if (!strcmp(arg, "--show-notes")) {
1370 + } else if (!strcmp(arg, "--show-notes") || !strcmp(arg, "--notes")) {
1371 revs->show_notes = 1;
1372 revs->show_notes_given = 1;
1373 revs->notes_opt.use_default_notes = 1;
1374 - } else if (!prefixcmp(arg, "--show-notes=")) {
1374 + } else if (!prefixcmp(arg, "--show-notes=") ||
1375 + !prefixcmp(arg, "--notes=")) {
1376 struct strbuf buf = STRBUF_INIT;
1377 revs->show_notes = 1;
1378 revs->show_notes_given = 1;
1378 - if (revs->notes_opt.use_default_notes < 0)
1379 - revs->notes_opt.use_default_notes = 1;
1380 - strbuf_addstr(&buf, arg+13);
1379 + if (!prefixcmp(arg, "--show-notes")) {
1380 + if (revs->notes_opt.use_default_notes < 0)
1381 + revs->notes_opt.use_default_notes = 1;
1382 + strbuf_addstr(&buf, arg+13);
1383 + }
1384 + else
1385 + strbuf_addstr(&buf, arg+8);
1386 expand_notes_ref(&buf);
1387 string_list_append(&revs->notes_opt.extra_notes_refs,
1388 strbuf_detach(&buf, NULL));
t/t3301-notes.sh
+22
@@ -247,6 +247,28 @@ do
247 '
248 done
249
250 +test_expect_success 'setup alternate notes ref' '
251 + git notes --ref=alternate add -m alternate
252 +'
253 +
254 +test_expect_success 'git log --notes shows default notes' '
255 + git log -1 --notes >output &&
256 + grep xyzzy output &&
257 + ! grep alternate output
258 +'
259 +
260 +test_expect_success 'git log --notes=X shows only X' '
261 + git log -1 --notes=alternate >output &&
262 + ! grep xyzzy output &&
263 + grep alternate output
264 +'
265 +
266 +test_expect_success 'git log --notes --notes=X shows both' '
267 + git log -1 --notes --notes=alternate >output &&
268 + grep xyzzy output &&
269 + grep alternate output
270 +'
271 +
272 test_expect_success 'create -m notes (setup)' '
273 : > a5 &&
274 git add a5 &&