@matheusbsbs / matheus-bagliano / commits / 3a03cf6b1d
Fork 0

notes: refactor display notes default handling

This is in preparation for more notes-related revision command-line options. The "suppress_default_notes" option is renamed to "use_default_notes", and is now a tri-state with values less than one indicating "not set". If the value is "not set", then we show default refs if and only if no other refs were given. 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 3a03cf6b1d1cf5d05edec1781446a26782eaff09
3 files changed +10 -4
notes.c
+2 -1
@@ -1053,7 +1053,8 @@ void init_display_notes(struct display_notes_opt *opt)
1053
1054 assert(!display_notes_trees);
1055
1056 - if (!opt || !opt->suppress_default_notes) {
1056 + if (!opt || opt->use_default_notes > 0 ||
1057 + (opt->use_default_notes == -1 && !opt->extra_notes_refs.nr)) {
1058 string_list_append(&display_notes_refs, default_notes_ref());
1059 display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);
1060 if (display_ref_env) {
notes.h
+1 -1
@@ -258,7 +258,7 @@ void format_note(struct notes_tree *t, const unsigned char *object_sha1,
258 struct string_list;
259
260 struct display_notes_opt {
261 - unsigned int suppress_default_notes:1;
261 + int use_default_notes;
262 struct string_list extra_notes_refs;
263 };
264
revision.c
+7 -2
@@ -955,6 +955,8 @@ void init_revisions(struct rev_info *revs, const char *prefix)
955 revs->diffopt.prefix = prefix;
956 revs->diffopt.prefix_length = strlen(prefix);
957 }
958 +
959 + revs->notes_opt.use_default_notes = -1;
960 }
961
962 static void add_pending_commit_list(struct rev_info *revs,
@@ -1368,10 +1370,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1370 } else if (!strcmp(arg, "--show-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=")) {
1375 struct strbuf buf = STRBUF_INIT;
1376 revs->show_notes = 1;
1377 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);
1381 expand_notes_ref(&buf);
1382 string_list_append(&revs->notes_opt.extra_notes_refs,
@@ -1381,9 +1386,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1386 revs->show_notes_given = 1;
1387 } else if (!strcmp(arg, "--standard-notes")) {
1388 revs->show_notes_given = 1;
1384 - revs->notes_opt.suppress_default_notes = 0;
1389 + revs->notes_opt.use_default_notes = 1;
1390 } else if (!strcmp(arg, "--no-standard-notes")) {
1386 - revs->notes_opt.suppress_default_notes = 1;
1391 + revs->notes_opt.use_default_notes = 0;
1392 } else if (!strcmp(arg, "--oneline")) {
1393 revs->verbose_header = 1;
1394 get_commit_format("oneline", revs);