git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Damien Robert <damien.olivier.robert@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Karthik Nayak <karthik.188@gmail.com>,
	Jeff Hostetler <jeffhost@microsoft.com>,
	"brian m. carlson" <sandals@crustytoothpaste.net>
Subject: Re: [PATCH 1/1] Fix %(push:track) in ref-filter
Date: Tue, 16 Apr 2019 17:48:43 -0400	[thread overview]
Message-ID: <20190416214842.GA21429@sigill.intra.peff.net> (raw)
In-Reply-To: <20190416123944.vtoremaitywtmkhj@mithrim>

On Tue, Apr 16, 2019 at 02:39:45PM +0200, Damien Robert wrote:

> > Or perhaps it argues for just giving access to the more generic stat_*
> > function, and letting callers pass in a flag for push vs upstream (and
> > either leaving stat_tracking_info() as a wrapper, or just updating its
> > few callers).
> 
> So I went ahead with modifying `stat_tracking_info` to accept a 'for_push'
> flag, and updated the few callers. This means that `stat_compare_info` is
> only used by `stat_tracking_info` so I could reinline it, but I guess it
> could still be useful latter.

Reading this paragraph, my gut reaction was to say that it should stay
as a single function. But actually looking at the code, I think it is a
bit nicer to separate out "compare these two branches" from "figure out
which branches to compare".

The name "compare_info" is a bit vague. Perhaps "stat_branch_pair" or
something would be more descriptive.

> > Also, since this is an internal helper function for the file, we should
> > mark it as static.
> 
> Yes. In fact in the first version of the patch I would call
> `stat_compare_info` directly in `ref_filter.c` so I needed to export it in
> `remote.h`, and then when I changed the patch I forgot to make it static.

Heh. I wondered if that might have been the reason.

> > Thanks for working on this.
> 
> You are welcome. What's the standard way to acknowledge your help in
> the Foo-By: trailers? I did not put a Reviewed-By: because you reviewed the
> previous patch, not the current one :)

Right, Reviewed-by wouldn't be quite right. As Christian noted,
Helped-by can be used for this (but I am also fine without credit;
suggestions are a normal part of review).

Overall the patch looks good to me. I have a few extremely minor nits:

> Subject: [v2 PATCH 1/1] Fix %(push:track) in ref-filter

We'd usually say "area: do something" here, and it's nice to stay
consistent so that reading --oneline output is easy. And it's nice if we
can avoid vague terms like "fix". Maybe:

 ref-filter: use correct branch for %(push:track)

or something?

> This bug was not detected in t/t6300-for-each-ref.sh because in the test
> for push:track, both the upstream and the push branches were behind by 1
> from the local branch. Change the test so that the upstream branch is
> behind by 1 while the push branch is ahead by 1. This allows us to test
> that %(push:track) refer to the correct branch.

s/refer/&s/

> This change the expected value of some following tests (by introducing
> new references), so update them too.

s/change/&s/

>  	if (abf != AHEAD_BEHIND_FULL)
> -		BUG("stat_tracking_info: invalid abf '%d'", abf);
> +		BUG("stat_compare_info: invalid abf '%d'", abf);

If we do the name change I mentioned above, don't forger this line. :)

> +int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
> +		       const char **upstream_name, int for_push,
> +		       enum ahead_behind_flags abf)
> +{

Is it worth changing "upstream_name" since it sometimes is now not
%(upstream)?

> @@ -1977,7 +2003,7 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
>  	char *base;
>  	int upstream_is_gone = 0;
>  
> -	sti = stat_tracking_info(branch, &ours, &theirs, &full_base, abf);
> +	sti = stat_tracking_info(branch, &ours, &theirs, &full_base, 0, abf);

I was tempted to suggest doing this refactor as a separate patch, so
that we'd see less noise in the diff. But in fact half of the callers
we'd have to touch are ones that would be modified to use for_push
anyway. So I think it makes sense to just keep it all together as a
single unit.

> diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
> [...]
> @@ -594,6 +603,7 @@ $(git rev-parse refs/tags/bogo) <committer@example.com> refs/tags/bogo
>  $(git rev-parse refs/tags/master) <committer@example.com> refs/tags/master
>  EOF
>  
> +
>  test_expect_success 'Verify sort with multiple keys' '
>  	git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
>  		refs/tags/bogo refs/tags/master > actual &&

Leftover stray whitespace?

For any one of those nits I'd probably say it was not worth a re-roll
(and the maintainer could adjust them when he picks up the patch).  But
there are just enough that it's probably worth making his life easier
with a v3.

You can put my Reviewed-by on it, too. :)

-Peff

  parent reply	other threads:[~2019-04-16 21:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-15 21:04 [PATCH 0/1] Fix a bug in ref-filter Damien Robert
2019-04-15 21:04 ` [PATCH 1/1] Fix %(push:track) " Damien Robert
2019-04-15 22:01   ` Jeff King
2019-04-16 12:39     ` Damien Robert
2019-04-16 14:13       ` Christian Couder
2019-04-16 21:48       ` Jeff King [this message]
2019-04-17  8:17         ` Damien Robert
2019-04-18  0:23           ` Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20190416214842.GA21429@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=damien.olivier.robert@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jeffhost@microsoft.com \
    --cc=karthik.188@gmail.com \
    --cc=sandals@crustytoothpaste.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).