From 03bb5789cd97de989897e1c9de71a2831ada0544 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 29 Mar 2011 16:55:32 -0400 Subject: [PATCH 1/8] notes: make expand_notes_ref globally accessible This function is useful for other commands besides "git notes" which want to let users refer to notes by their shorthand name. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/notes.c | 10 ---------- notes.c | 10 ++++++++++ notes.h | 3 +++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/builtin/notes.c b/builtin/notes.c index a0f310b72..62276072f 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -100,16 +100,6 @@ struct msg_arg { struct strbuf buf; }; -static void expand_notes_ref(struct strbuf *sb) -{ - if (!prefixcmp(sb->buf, "refs/notes/")) - return; /* we're happy */ - else if (!prefixcmp(sb->buf, "notes/")) - strbuf_insert(sb, 0, "refs/", 5); - else - strbuf_insert(sb, 0, "refs/notes/", 11); -} - static int list_each_note(const unsigned char *object_sha1, const unsigned char *note_sha1, char *note_path, void *cb_data) diff --git a/notes.c b/notes.c index a013c1bc6..f6b9b6a72 100644 --- a/notes.c +++ b/notes.c @@ -1285,3 +1285,13 @@ int copy_note(struct notes_tree *t, return 0; } + +void expand_notes_ref(struct strbuf *sb) +{ + if (!prefixcmp(sb->buf, "refs/notes/")) + return; /* we're happy */ + else if (!prefixcmp(sb->buf, "notes/")) + strbuf_insert(sb, 0, "refs/", 5); + else + strbuf_insert(sb, 0, "refs/notes/", 11); +} diff --git a/notes.h b/notes.h index 83bd6e0ec..60bdf289a 100644 --- a/notes.h +++ b/notes.h @@ -307,4 +307,7 @@ void string_list_add_refs_by_glob(struct string_list *list, const char *glob); void string_list_add_refs_from_colon_sep(struct string_list *list, const char *globs); +/* Expand inplace a note ref like "foo" or "notes/foo" into "refs/notes/foo" */ +void expand_notes_ref(struct strbuf *sb); + #endif From c063f0a973832784f09a6901eac9501b6f796bde Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 29 Mar 2011 16:56:04 -0400 Subject: [PATCH 2/8] revision.c: refactor notes ref expansion No need to do it ourselves when there is a library function. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- revision.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/revision.c b/revision.c index 0f38364cf..5826e5d59 100644 --- a/revision.c +++ b/revision.c @@ -1374,13 +1374,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->show_notes_given = 1; if (!revs->notes_opt.extra_notes_refs) revs->notes_opt.extra_notes_refs = xcalloc(1, sizeof(struct string_list)); - if (!prefixcmp(arg+13, "refs/")) - /* happy */; - else if (!prefixcmp(arg+13, "notes/")) - strbuf_addstr(&buf, "refs/"); - else - strbuf_addstr(&buf, "refs/notes/"); strbuf_addstr(&buf, arg+13); + expand_notes_ref(&buf); string_list_append(revs->notes_opt.extra_notes_refs, strbuf_detach(&buf, NULL)); } else if (!strcmp(arg, "--no-notes")) { From 304cc11c6566cf22e811aa791988c61b6d291973 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 29 Mar 2011 16:56:53 -0400 Subject: [PATCH 3/8] notes: refactor display notes extra refs field There's no need to use an extra pointer, which just ends up leaking memory. The fact that the list is empty tells us the same thing. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- notes.c | 4 ++-- notes.h | 4 +++- revision.c | 4 +--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/notes.c b/notes.c index f6b9b6a72..2ec604c1d 100644 --- a/notes.c +++ b/notes.c @@ -1066,9 +1066,9 @@ void init_display_notes(struct display_notes_opt *opt) git_config(notes_display_config, &load_config_refs); - if (opt && opt->extra_notes_refs) { + if (opt) { struct string_list_item *item; - for_each_string_list_item(item, opt->extra_notes_refs) + for_each_string_list_item(item, &opt->extra_notes_refs) string_list_add_refs_by_glob(&display_notes_refs, item->string); } diff --git a/notes.h b/notes.h index 60bdf289a..7ae3eefe0 100644 --- a/notes.h +++ b/notes.h @@ -1,6 +1,8 @@ #ifndef NOTES_H #define NOTES_H +#include "string-list.h" + /* * Function type for combining two notes annotating the same object. * @@ -257,7 +259,7 @@ struct string_list; struct display_notes_opt { unsigned int suppress_default_notes:1; - struct string_list *extra_notes_refs; + struct string_list extra_notes_refs; }; /* diff --git a/revision.c b/revision.c index 5826e5d59..24b89ebfd 100644 --- a/revision.c +++ b/revision.c @@ -1372,11 +1372,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg struct strbuf buf = STRBUF_INIT; revs->show_notes = 1; revs->show_notes_given = 1; - if (!revs->notes_opt.extra_notes_refs) - revs->notes_opt.extra_notes_refs = xcalloc(1, sizeof(struct string_list)); strbuf_addstr(&buf, arg+13); expand_notes_ref(&buf); - string_list_append(revs->notes_opt.extra_notes_refs, + string_list_append(&revs->notes_opt.extra_notes_refs, strbuf_detach(&buf, NULL)); } else if (!strcmp(arg, "--no-notes")) { revs->show_notes = 0; From 3a03cf6b1d1cf5d05edec1781446a26782eaff09 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 29 Mar 2011 16:57:27 -0400 Subject: [PATCH 4/8] 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 Signed-off-by: Junio C Hamano --- notes.c | 3 ++- notes.h | 2 +- revision.c | 9 +++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/notes.c b/notes.c index 2ec604c1d..f6ce8489d 100644 --- a/notes.c +++ b/notes.c @@ -1053,7 +1053,8 @@ void init_display_notes(struct display_notes_opt *opt) assert(!display_notes_trees); - if (!opt || !opt->suppress_default_notes) { + if (!opt || opt->use_default_notes > 0 || + (opt->use_default_notes == -1 && !opt->extra_notes_refs.nr)) { string_list_append(&display_notes_refs, default_notes_ref()); display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT); if (display_ref_env) { diff --git a/notes.h b/notes.h index 7ae3eefe0..c716694b9 100644 --- a/notes.h +++ b/notes.h @@ -258,7 +258,7 @@ void format_note(struct notes_tree *t, const unsigned char *object_sha1, struct string_list; struct display_notes_opt { - unsigned int suppress_default_notes:1; + int use_default_notes; struct string_list extra_notes_refs; }; diff --git a/revision.c b/revision.c index 24b89ebfd..315a7f431 100644 --- a/revision.c +++ b/revision.c @@ -955,6 +955,8 @@ void init_revisions(struct rev_info *revs, const char *prefix) revs->diffopt.prefix = prefix; revs->diffopt.prefix_length = strlen(prefix); } + + revs->notes_opt.use_default_notes = -1; } 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 } else if (!strcmp(arg, "--show-notes")) { revs->show_notes = 1; revs->show_notes_given = 1; + revs->notes_opt.use_default_notes = 1; } else if (!prefixcmp(arg, "--show-notes=")) { struct strbuf buf = STRBUF_INIT; revs->show_notes = 1; revs->show_notes_given = 1; + if (revs->notes_opt.use_default_notes < 0) + revs->notes_opt.use_default_notes = 1; strbuf_addstr(&buf, arg+13); expand_notes_ref(&buf); 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 revs->show_notes_given = 1; } else if (!strcmp(arg, "--standard-notes")) { revs->show_notes_given = 1; - revs->notes_opt.suppress_default_notes = 0; + revs->notes_opt.use_default_notes = 1; } else if (!strcmp(arg, "--no-standard-notes")) { - revs->notes_opt.suppress_default_notes = 1; + revs->notes_opt.use_default_notes = 0; } else if (!strcmp(arg, "--oneline")) { revs->verbose_header = 1; get_commit_format("oneline", revs); From 7249e91287443c02b2c7eed272a579dae44984ad Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 29 Mar 2011 16:57:47 -0400 Subject: [PATCH 5/8] revision.c: support --notes command-line option We already have --show-notes, but it has a few shortcomings: 1. Using --show-notes= 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=" does not imply showing the default notes. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- revision.c | 15 ++++++++++----- t/t3301-notes.sh | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/revision.c b/revision.c index 315a7f431..c4ffee464 100644 --- a/revision.c +++ b/revision.c @@ -1367,17 +1367,22 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->verbose_header = 1; revs->pretty_given = 1; get_commit_format(arg+9, revs); - } else if (!strcmp(arg, "--show-notes")) { + } else if (!strcmp(arg, "--show-notes") || !strcmp(arg, "--notes")) { revs->show_notes = 1; revs->show_notes_given = 1; revs->notes_opt.use_default_notes = 1; - } else if (!prefixcmp(arg, "--show-notes=")) { + } else if (!prefixcmp(arg, "--show-notes=") || + !prefixcmp(arg, "--notes=")) { struct strbuf buf = STRBUF_INIT; revs->show_notes = 1; revs->show_notes_given = 1; - if (revs->notes_opt.use_default_notes < 0) - revs->notes_opt.use_default_notes = 1; - strbuf_addstr(&buf, arg+13); + if (!prefixcmp(arg, "--show-notes")) { + if (revs->notes_opt.use_default_notes < 0) + revs->notes_opt.use_default_notes = 1; + strbuf_addstr(&buf, arg+13); + } + else + strbuf_addstr(&buf, arg+8); expand_notes_ref(&buf); string_list_append(&revs->notes_opt.extra_notes_refs, strbuf_detach(&buf, NULL)); diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index 1921ca3a7..f0e7a5812 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -247,6 +247,28 @@ do ' done +test_expect_success 'setup alternate notes ref' ' + git notes --ref=alternate add -m alternate +' + +test_expect_success 'git log --notes shows default notes' ' + git log -1 --notes >output && + grep xyzzy output && + ! grep alternate output +' + +test_expect_success 'git log --notes=X shows only X' ' + git log -1 --notes=alternate >output && + ! grep xyzzy output && + grep alternate output +' + +test_expect_success 'git log --notes --notes=X shows both' ' + git log -1 --notes --notes=alternate >output && + grep xyzzy output && + grep alternate output +' + test_expect_success 'create -m notes (setup)' ' : > a5 && git add a5 && From 92e0d42539a34e90f5c9bf29eb741f0d87173027 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 29 Mar 2011 16:59:42 -0400 Subject: [PATCH 6/8] revision.c: make --no-notes reset --notes list With most command line options, later instances of an option override earlier ones. With cumulative options like "--notes", however, there is no way to say "forget the --notes I gave you before". Let's have --no-notes trigger this forgetting, so that: git log --notes=foo --no-notes --notes=bar will show only the "bar" notes. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- revision.c | 6 ++++++ t/t3301-notes.sh | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/revision.c b/revision.c index c4ffee464..541f09e21 100644 --- a/revision.c +++ b/revision.c @@ -1389,6 +1389,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg } else if (!strcmp(arg, "--no-notes")) { revs->show_notes = 0; revs->show_notes_given = 1; + revs->notes_opt.use_default_notes = -1; + /* we have been strdup'ing ourselves, so trick + * string_list into free()ing strings */ + revs->notes_opt.extra_notes_refs.strdup_strings = 1; + string_list_clear(&revs->notes_opt.extra_notes_refs, 0); + revs->notes_opt.extra_notes_refs.strdup_strings = 0; } else if (!strcmp(arg, "--standard-notes")) { revs->show_notes_given = 1; revs->notes_opt.use_default_notes = 1; diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index f0e7a5812..8600db7ed 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -269,6 +269,22 @@ test_expect_success 'git log --notes --notes=X shows both' ' grep alternate output ' +test_expect_success 'git log --no-notes resets default state' ' + git log -1 --notes --notes=alternate \ + --no-notes --notes=alternate \ + >output && + ! grep xyzzy output && + grep alternate output +' + +test_expect_success 'git log --no-notes resets ref list' ' + git log -1 --notes --notes=alternate \ + --no-notes --notes \ + >output && + grep xyzzy output && + ! grep alternate output +' + test_expect_success 'create -m notes (setup)' ' : > a5 && git add a5 && From ab18b2c0df93b518ff9591d69e5e607fee718814 Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Wed, 30 Mar 2011 02:57:19 +0200 Subject: [PATCH 7/8] log/pretty-options: Document --[no-]notes and deprecate old notes options Document the behavior or the new --notes, --notes= and --no-notes options, and list --show-notes[=] and --[no-]standard-notes options as deprecated. Signed-off-by: Johan Herland Acked-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/git-log.txt | 4 ++-- Documentation/pretty-options.txt | 35 +++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index 2c8402883..de5c0d37a 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -178,9 +178,9 @@ May be an unabbreviated ref name or a glob and may be specified multiple times. A warning will be issued for refs that do not exist, but a glob that does not match any refs is silently ignored. + -This setting can be disabled by the `--no-standard-notes` option, +This setting can be disabled by the `--no-notes` option, overridden by the 'GIT_NOTES_DISPLAY_REF' environment variable, -and supplemented by the `--show-notes` option. +and overridden by the `--notes=` option. GIT --- diff --git a/Documentation/pretty-options.txt b/Documentation/pretty-options.txt index 50923e2ce..d5c977262 100644 --- a/Documentation/pretty-options.txt +++ b/Documentation/pretty-options.txt @@ -30,19 +30,34 @@ people using 80-column terminals. preferred by the user. For non plumbing commands this defaults to UTF-8. ---no-notes:: ---show-notes[=]:: +--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`, `--format` nor `--oneline` option is - given on the command line. + there is no `--pretty`, `--format` nor `--oneline` option given + on the command line. ++ +By default, the notes shown are from the notes refs listed in the +'core.notesRef' and 'notes.displayRef' variables (or corresponding +environment overrides). See linkgit:git-config[1] for more details. ++ +With an optional '' argument, show this notes ref instead of the +default notes ref(s). The ref is taken to be in `refs/notes/` if it +is not qualified. + -With an optional argument, add this ref to the list of notes. The ref -is taken to be in `refs/notes/` if it is not qualified. +Multiple --notes options can be combined to control which notes are +being displayed. Examples: "--notes=foo" will show only notes from +"refs/notes/foo"; "--notes=foo --notes" will show both notes from +"refs/notes/foo" and from the default notes ref(s). +--no-notes:: + Do not show notes. This negates the above `--notes` option, by + resetting the list of notes refs from which notes are shown. + Options are parsed in the order given on the command line, so e.g. + "--notes --notes=foo --no-notes --notes=bar" will only show notes + from "refs/notes/bar". + +--show-notes[=]:: --[no-]standard-notes:: - Enable or disable populating the notes ref list from the - 'core.notesRef' and 'notes.displayRef' variables (or - corresponding environment overrides). Enabled by default. - See linkgit:git-config[1]. + These options are deprecated. Use the above --notes/--no-notes + options instead. From 3925b575687f64d49bd777ba6f64557a56b838b6 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Thu, 14 Apr 2011 19:53:13 +0200 Subject: [PATCH 8/8] contrib/completion: --notes, --no-notes Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 840ae3876..7e6a3eee8 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1584,7 +1584,7 @@ __git_log_common_options=" __git_log_gitk_options=" --dense --sparse --full-history --simplify-merges --simplify-by-decoration - --left-right + --left-right --notes --no-notes " # Options that go well for log and shortlog (not gitk) __git_log_shortlog_options="