All of lore.kernel.org
 help / color / mirror / Atom feed
From: Taylor Blau <me@ttaylorr.com>
To: Jeff King <peff@peff.net>
Cc: Taylor Blau <me@ttaylorr.com>, Junio C Hamano <gitster@pobox.com>,
	git@vger.kernel.org, vd@FreeBSD.org
Subject: Re: [PATCH] diff-tree.c: load notes machinery when required
Date: Mon, 20 Apr 2020 18:03:50 -0600	[thread overview]
Message-ID: <20200421000350.GA19835@syl.local> (raw)
In-Reply-To: <20200416045630.GA21547@coredump.intra.peff.net>

On Thu, Apr 16, 2020 at 12:56:30AM -0400, Jeff King wrote:
> On Wed, Apr 15, 2020 at 06:37:38PM -0600, Taylor Blau wrote:
>
> > Since its introduction in 7249e91 (revision.c: support --notes
> > command-line option, 2011-03-29), combining '--notes' with any option
> > that causes us to format notes (e.g., '--pretty', '--format="%N"', etc)
> > results in a failed assertion at runtime.
> >
> >   $ git rev-list HEAD | git diff-tree --stdin --pretty=medium --notes
> >   commit 8f3d9f354286745c751374f5f1fcafee6b3f3136
> >   git: notes.c:1308: format_display_notes: Assertion `display_notes_trees' failed.
> >   Aborted
> >
> > This failure is due to diff-tree not calling 'load_display_notes' to
> > initialize the notes machinery.
> >
> > Ordinarily, this failure isn't triggered, because it requires passing
> > both '--notes' and another of the above mentioned options. In the case
> > of '--pretty', for example, we set 'opt->verbose_header', causing
> > 'show_log()' to eventually call 'format_display_notes()', which expects
> > a non-NULL 'display_note_trees'.
>
> This looks much better. One question, though...
>
> > @@ -127,6 +128,14 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
> >  	precompose_argv(argc, argv);
> >  	argc = setup_revisions(argc, argv, opt, &s_r_opt);
> >
> > +	memset(&w, 0, sizeof(w));
> > +	userformat_find_requirements(NULL, &w);
> > +
> > +	if (!opt->show_notes_given && (!opt->pretty_given || w.notes))
> > +		opt->show_notes = 1;
> > +	if (opt->show_notes)
> > +		load_display_notes(&opt->notes_opt);
> > +
>
> I assume these lines were lifted from builtin/log.c. But what is
> pretty_given doing here?
>
> In git-log, it's turning on notes for the default case when no format is
> given. But here, if no format has been given we _wouldn't_ want to show
> notes.
>
> I think it's relatively harmless, since our default format is not to do
> any pretty-printing, and therefore we wouldn't look at the notes. But it
> does cause us to call load_display_notes() when we don't need to. I
> think that conditional can be simplified to just:
>
>   if (!opt->show_notes_given && w.notes)
> 	opt->show_notes = 1;

Yep, your reasoning makes perfect sense, and I think that what you
suggested is exactly right. (The original code was indeed lifted from
'git log'...)

> > Fix this by initializing the notes machinery after parsing our options,
> > and harden this behavior against regression with a test in t4013. (Note
> > that the added ref in this test requires updating two unrelated tests
> > which use 'log --all', and thus need to learn about the new refs).
>
> This makes the test update rather hard to follow, but I don't think
> there's an easy way around it. I wondered if we could insert and remove
> our notes just for our tests, but it's hard to do with the big while
> loop in that script.
>
> I also thought it might not be that bad to just add a few tests at the
> end, but there are some complications (like removing sha1s from the
> output; easily done with a custom format, but the point is to test
> --pretty).
>
> So what you have is probably the most sensible thing (and the new commit
> would make it easier to test other commands around notes later, if we
> chose to).

Yeah :/.

> > @@ -398,6 +407,8 @@ diff --no-index --raw --no-abbrev dir2 dir
> >
> >  diff-tree --pretty --root --stat --compact-summary initial
> >  diff-tree --pretty -R --root --stat --compact-summary initial
> > +diff-tree --pretty --notes note
> > +diff-tree --format=%N note
> >  diff-tree --stat --compact-summary initial mode
> >  diff-tree -R --stat --compact-summary initial mode
>
> Perhaps worth testing that:
>
>   diff-tree --pretty note
>
> does not print any notes by default?

Good idea.

> -Peff

I'll send an updated patch as a response in a separate email shortly...

Thanks,
Taylor

  reply	other threads:[~2020-04-21  0:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-16  0:37 [PATCH] diff-tree.c: load notes machinery when required Taylor Blau
2020-04-16  1:03 ` Junio C Hamano
2020-04-16  4:56 ` Jeff King
2020-04-21  0:03   ` Taylor Blau [this message]
2020-04-21  0:05   ` Taylor Blau
2020-04-21  0:06     ` Jeff King
2020-04-21  0:13       ` Taylor Blau
2020-04-21  0:19         ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200421000350.GA19835@syl.local \
    --to=me@ttaylorr.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=vd@FreeBSD.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.