* [PATCH] Fix `git rev-list --show-notes HEAD` when there are no notes @ 2015-08-22 15:14 Johannes Schindelin 2015-08-22 16:30 ` Johan Herland 2015-08-23 17:43 ` Jeff King 0 siblings, 2 replies; 7+ messages in thread From: Johannes Schindelin @ 2015-08-22 15:14 UTC (permalink / raw) To: Junio C Hamano, Git Mailing List The `format_display_notes()` function clearly assumes that the data structure holding the notes has been initialized already, i.e. that the `display_notes_trees` variable is no longer `NULL`. However, when there are no notes whatsoever, this variable is still `NULL`, even after initialization. So let's be graceful and just return if that data structure is `NULL`. Reported in https://github.com/msysgit/git/issues/363. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> --- notes.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/notes.c b/notes.c index df08209..24a335a 100644 --- a/notes.c +++ b/notes.c @@ -1266,7 +1266,10 @@ void format_display_notes(const unsigned char *object_sha1, struct strbuf *sb, const char *output_encoding, int raw) { int i; - assert(display_notes_trees); + + if (!display_notes_trees) + return; + for (i = 0; display_notes_trees[i]; i++) format_note(display_notes_trees[i], object_sha1, sb, output_encoding, raw); -- 2.3.1.windows.1.9.g8c01ab4 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix `git rev-list --show-notes HEAD` when there are no notes 2015-08-22 15:14 [PATCH] Fix `git rev-list --show-notes HEAD` when there are no notes Johannes Schindelin @ 2015-08-22 16:30 ` Johan Herland 2015-08-23 17:43 ` Jeff King 1 sibling, 0 replies; 7+ messages in thread From: Johan Herland @ 2015-08-22 16:30 UTC (permalink / raw) To: Johannes Schindelin; +Cc: Junio C Hamano, Git Mailing List On Sat, Aug 22, 2015 at 5:14 PM, Johannes Schindelin <johannes.schindelin@gmx.de> wrote: > The `format_display_notes()` function clearly assumes that the data > structure holding the notes has been initialized already, i.e. that the > `display_notes_trees` variable is no longer `NULL`. > > However, when there are no notes whatsoever, this variable is still > `NULL`, even after initialization. > > So let's be graceful and just return if that data structure is `NULL`. > > Reported in https://github.com/msysgit/git/issues/363. > > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Acked-by: Johan Herland <johan@herland.net> -- Johan Herland, <johan@herland.net> www.herland.net ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix `git rev-list --show-notes HEAD` when there are no notes 2015-08-22 15:14 [PATCH] Fix `git rev-list --show-notes HEAD` when there are no notes Johannes Schindelin 2015-08-22 16:30 ` Johan Herland @ 2015-08-23 17:43 ` Jeff King 2015-08-23 17:56 ` [PATCH] rev-list: make it obvious that we do not support notes Jeff King 2015-08-24 10:23 ` [PATCH] Fix `git rev-list --show-notes HEAD` when there are no notes Johannes Schindelin 1 sibling, 2 replies; 7+ messages in thread From: Jeff King @ 2015-08-23 17:43 UTC (permalink / raw) To: Johannes Schindelin; +Cc: Junio C Hamano, Git Mailing List On Sat, Aug 22, 2015 at 05:14:39PM +0200, Johannes Schindelin wrote: > The `format_display_notes()` function clearly assumes that the data > structure holding the notes has been initialized already, i.e. that the > `display_notes_trees` variable is no longer `NULL`. > > However, when there are no notes whatsoever, this variable is still > `NULL`, even after initialization. > > So let's be graceful and just return if that data structure is `NULL`. Hrm. This is supposed to be made non-NULL by calling init_display_notes. The "git-log" code does this properly, and can show notes. The "rev-list" code does not, and hits this assert. But that also means that it cannot actually _show_ notes, and your patch is papering over the problem. I would think we would need something more like this: diff --git a/builtin/rev-list.c b/builtin/rev-list.c index ff84a82..fc73a6f 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -279,6 +279,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) int bisect_show_vars = 0; int bisect_find_all = 0; int use_bitmap_index = 0; + struct userformat_want w; git_config(git_default_config, NULL); init_revisions(&revs, prefix); @@ -349,6 +350,14 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) revs.diff) usage(rev_list_usage); + memset(&w, 0, sizeof(w)); + userformat_find_requirements(NULL, &w); + + if (!revs.show_notes_given && w.notes) + revs.show_notes = 1; + if (revs.show_notes) + init_display_notes(&revs.notes_opt); + save_commit_buffer = (revs.verbose_header || revs.grep_filter.pattern_list || revs.grep_filter.header_list); but it looks like that is not enough to convince the pretty-printer to actually show notes (I suspect we need something like the pretty_ctx->notes_message setup that is in show_log()). I don't know how deeply anybody _cares_ about showing notes via rev-list. It has clearly never worked. But rather than silently accepting --show-notes (and not showing any notes!), perhaps we should tell the user that it does not work. Likewise, the "%N" --format specifier never expands in rev-list, and should probably be removed from the rev-list documentation. Although... > Reported in https://github.com/msysgit/git/issues/363. After reading your subject, I wondered why "git rev-list --show-notes HEAD" did not crash for me (whether or not I had notes). But the key element from that issue is the addition of "--grep", which is what triggers us to actually look at the notes (since rev-list otherwise does not support displaying them). And that _does_ work with my patch above. So perhaps that is useful, though again, it has never worked in the past (and with your patch, it would silently return no results, whether the grep matched or not). Of course it's a terrible interface to make "--show-notes --grep" grep the notes, but not actually _show_ them. :-/ > diff --git a/notes.c b/notes.c > index df08209..24a335a 100644 > --- a/notes.c > +++ b/notes.c > @@ -1266,7 +1266,10 @@ void format_display_notes(const unsigned char *object_sha1, > struct strbuf *sb, const char *output_encoding, int raw) > { > int i; > - assert(display_notes_trees); > + > + if (!display_notes_trees) > + return; > + So I'm not really in favor of this approach, but if we do go that route, the comment above the declaration of format_display_notes needs to be updated. -Peff ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH] rev-list: make it obvious that we do not support notes 2015-08-23 17:43 ` Jeff King @ 2015-08-23 17:56 ` Jeff King 2015-08-24 10:23 ` [PATCH] Fix `git rev-list --show-notes HEAD` when there are no notes Johannes Schindelin 1 sibling, 0 replies; 7+ messages in thread From: Jeff King @ 2015-08-23 17:56 UTC (permalink / raw) To: Johannes Schindelin; +Cc: Junio C Hamano, Git Mailing List On Sun, Aug 23, 2015 at 01:43:09PM -0400, Jeff King wrote: > I don't know how deeply anybody _cares_ about showing notes via > rev-list. It has clearly never worked. But rather than silently > accepting --show-notes (and not showing any notes!), perhaps we should > tell the user that it does not work. Likewise, the "%N" --format > specifier never expands in rev-list, and should probably be removed from > the rev-list documentation. I think that would look like this. IMHO this is a strict improvement on the current state. I would be happier still if somebody wanted to plumb the notes options through for rev-list, but I am not personally interested in spending the time on that. -- >8 -- Subject: rev-list: make it obvious that we do not support notes The rev-list command does not have the internal infrastructure to display notes. Running: git rev-list --notes HEAD will silently ignore the "--notes" option. Running: git rev-list --notes --grep=. HEAD will crash on an assert. Running: git rev-list --format=%N HEAD will place a literal "%N" in the output (it does not even expand to an empty string). Let's have rev-list tell the user that it cannot fill the user's request, rather than silently producing wrong data. Likewise, let's remove mention of the notes options from the rev-list documentation. Signed-off-by: Jeff King <peff@peff.net> --- Documentation/pretty-formats.txt | 2 ++ Documentation/pretty-options.txt | 2 ++ Documentation/rev-list-options.txt | 2 ++ builtin/rev-list.c | 3 +++ 4 files changed, 9 insertions(+) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index dc865cb..671cebd 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -139,7 +139,9 @@ The placeholders are: - '%f': sanitized subject line, suitable for a filename - '%b': body - '%B': raw body (unwrapped subject and body) +ifndef::git-rev-list[] - '%N': commit notes +endif::git-rev-list[] - '%GG': raw verification message from GPG for a signed commit - '%G?': show "G" for a Good signature, "B" for a Bad signature, "U" for a good, untrusted signature and "N" for no signature diff --git a/Documentation/pretty-options.txt b/Documentation/pretty-options.txt index 642af6e..8d6c5ce 100644 --- a/Documentation/pretty-options.txt +++ b/Documentation/pretty-options.txt @@ -42,6 +42,7 @@ people using 80-column terminals. verbatim; this means that invalid sequences in the original commit may be copied to the output. +ifndef::git-rev-list[] --notes[=<ref>]:: Show the notes (see linkgit:git-notes[1]) that annotate the commit, when showing the commit log message. This is the default @@ -73,6 +74,7 @@ being displayed. Examples: "--notes=foo" will show only notes from --[no-]standard-notes:: These options are deprecated. Use the above --notes/--no-notes options instead. +endif::git-rev-list[] --show-signature:: Check the validity of a signed commit object by passing the signature diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index a9b808f..f1c5220 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -58,9 +58,11 @@ endif::git-rev-list[] more than one `--grep=<pattern>`, commits whose message matches any of the given patterns are chosen (but see `--all-match`). +ifndef::git-rev-list[] + When `--show-notes` is in effect, the message from the notes is matched as if it were part of the log message. +endif::git-rev-list[] --all-match:: Limit the commits output to ones that match all given `--grep`, diff --git a/builtin/rev-list.c b/builtin/rev-list.c index c0b4b53..d80d1ed 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -350,6 +350,9 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) revs.diff) usage(rev_list_usage); + if (revs.show_notes) + die(_("rev-list does not support display of notes")); + save_commit_buffer = (revs.verbose_header || revs.grep_filter.pattern_list || revs.grep_filter.header_list); -- 2.5.0.685.g0ca4974 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix `git rev-list --show-notes HEAD` when there are no notes 2015-08-23 17:43 ` Jeff King 2015-08-23 17:56 ` [PATCH] rev-list: make it obvious that we do not support notes Jeff King @ 2015-08-24 10:23 ` Johannes Schindelin 2015-08-24 14:43 ` Jeff King 1 sibling, 1 reply; 7+ messages in thread From: Johannes Schindelin @ 2015-08-24 10:23 UTC (permalink / raw) To: Jeff King; +Cc: Junio C Hamano, Git Mailing List Hi Peff, On 2015-08-23 19:43, Jeff King wrote: > On Sat, Aug 22, 2015 at 05:14:39PM +0200, Johannes Schindelin wrote: > >> The `format_display_notes()` function clearly assumes that the data >> structure holding the notes has been initialized already, i.e. that the >> `display_notes_trees` variable is no longer `NULL`. >> >> However, when there are no notes whatsoever, this variable is still >> `NULL`, even after initialization. >> >> So let's be graceful and just return if that data structure is `NULL`. > > Hrm. This is supposed to be made non-NULL by calling init_display_notes. > The "git-log" code does this properly, and can show notes. The > "rev-list" code does not, and hits this assert. But that also means that > it cannot actually _show_ notes, and your patch is papering over the > problem. Good point... > it looks like [patch] is not enough to convince the pretty-printer to > actually show notes (I suspect we need something like the > pretty_ctx->notes_message setup that is in show_log()). > > I don't know how deeply anybody _cares_ about showing notes via > rev-list. It has clearly never worked. But rather than silently > accepting --show-notes (and not showing any notes!), perhaps we should > tell the user that it does not work. Likewise, the "%N" --format > specifier never expands in rev-list, and should probably be removed from > the rev-list documentation. Hmpf. I really did not want to uncover yet another rabbit hole... >> Reported in https://github.com/msysgit/git/issues/363. > > After reading your subject, I wondered why "git rev-list --show-notes > HEAD" did not crash for me (whether or not I had notes). But the key > element from that issue is the addition of "--grep", which is what > triggers us to actually look at the notes (since rev-list otherwise does > not support displaying them). And that _does_ work with my patch above. > So perhaps that is useful, though again, it has never worked in the > past (and with your patch, it would silently return no results, whether > the grep matched or not). > > Of course it's a terrible interface to make "--show-notes --grep" grep > the notes, but not actually _show_ them. :-/ It is. > So I'm not really in favor of this approach, but if we do go that route, > the comment above the declaration of format_display_notes needs to be > updated. You're right. I think the best approach for now is to error out when `--show-notes` is passed to rev-list. Do you agree? Ciao, Dscho ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix `git rev-list --show-notes HEAD` when there are no notes 2015-08-24 10:23 ` [PATCH] Fix `git rev-list --show-notes HEAD` when there are no notes Johannes Schindelin @ 2015-08-24 14:43 ` Jeff King 2015-08-24 14:48 ` Johannes Schindelin 0 siblings, 1 reply; 7+ messages in thread From: Jeff King @ 2015-08-24 14:43 UTC (permalink / raw) To: Johannes Schindelin; +Cc: Junio C Hamano, Git Mailing List On Mon, Aug 24, 2015 at 12:23:52PM +0200, Johannes Schindelin wrote: > You're right. I think the best approach for now is to error out when > `--show-notes` is passed to rev-list. Do you agree? Yes (I imagine you didn't yet read my follow-up patch when you wrote this). :) -Peff ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix `git rev-list --show-notes HEAD` when there are no notes 2015-08-24 14:43 ` Jeff King @ 2015-08-24 14:48 ` Johannes Schindelin 0 siblings, 0 replies; 7+ messages in thread From: Johannes Schindelin @ 2015-08-24 14:48 UTC (permalink / raw) To: Jeff King; +Cc: Junio C Hamano, Git Mailing List Hi Peff, On 2015-08-24 16:43, Jeff King wrote: > On Mon, Aug 24, 2015 at 12:23:52PM +0200, Johannes Schindelin wrote: > >> You're right. I think the best approach for now is to error out when >> `--show-notes` is passed to rev-list. Do you agree? > > Yes (I imagine you didn't yet read my follow-up patch when you wrote > this). :) Yep, and I forgot to reply when I saw it. Thanks for continuing on that front! Ciao, Dscho ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-08-24 14:48 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-08-22 15:14 [PATCH] Fix `git rev-list --show-notes HEAD` when there are no notes Johannes Schindelin 2015-08-22 16:30 ` Johan Herland 2015-08-23 17:43 ` Jeff King 2015-08-23 17:56 ` [PATCH] rev-list: make it obvious that we do not support notes Jeff King 2015-08-24 10:23 ` [PATCH] Fix `git rev-list --show-notes HEAD` when there are no notes Johannes Schindelin 2015-08-24 14:43 ` Jeff King 2015-08-24 14:48 ` Johannes Schindelin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).