Fix a bug in ref-filter
cover Fix a bug in ref-filter
Dear git developers,
Testing the behaviour of git with respect to pushing and pulling, I noticed that %(push:track) in git for-each-ref reported the wrong value (ie the upstream's value rather than the push one).
This patch fixes that.
Please tell me if you would prefer I split this patch in two, one introducing stat_push_info in remote.c and the following one using it in ref-filter.c
Damien Robert (1):
Fix %(push:track) in ref-filter
ref-filter.c | 7 ++-- remote.c | 78 +++++++++++++++++++++++++++++++---------- remote.h | 2 ++ t/t6300-for-each-ref.sh | 12 ++++++- 4 files changed, 78 insertions(+), 21 deletions(-)
Signature · 1 line
Patched on top of v2.21.0-196-g041f5ea1cf (git version 2.21.0)
PATCH 1/1 Fix %(push:track) in ref-filter
In ref-filter.c, when processing the atom %(push:track), the ahead/behind values are computed using stat_tracking_info which refers to the upstream branch.
Fix that by introducing a new function stat_push_info in remote.c (exported in remote.h), which does the same thing but for the push branch. Factorise the ahead/behind computation of stat_tracking_info into stat_compare_info so that it can be reused for stat_push_info.
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 branch were ahead by 1. Change the test so that the upstream branch is ahead by 2 while the push branch is ahead by 1, this allow us to test that %(push:track) refer to the correct branch.
This change the expected value of some following tests, so update them too.
--- ref-filter.c | 7 ++-- remote.c | 79 +++++++++++++++++++++++++++++++---------- remote.h | 2 ++ t/t6300-for-each-ref.sh | 13 ++++++- 4 files changed, 80 insertions(+), 21 deletions(-)
ref-filter.c +5 -2
@@ -1391,8 +1391,11 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname,if (atom->u.remote_ref.option ==RR_REF ) *s =show_ref (&atom->u.remote_ref.refname, refname);else if (atom->u.remote_ref.option ==RR_TRACK ) { -if (stat_tracking_info (branch, &num_ours, &num_theirs, -NULL ,AHEAD_BEHIND_FULL ) <0 ) { +if ((atom->u.remote_ref.push ? +stat_push_info (branch, &num_ours, &num_theirs, +NULL ,AHEAD_BEHIND_FULL ) : +stat_tracking_info (branch, &num_ours, &num_theirs, +NULL ,AHEAD_BEHIND_FULL )) <0 ) { *s =xstrdup (msgs.gone); }else if (!num_ours && !num_theirs) *s =xstrdup ("" );
remote.c +61 -18
116 lines not on this page · raw message
remote.h +2 -0
@@ -254,6 +254,8 @@ enum ahead_behind_flags {/* Reporting of tracking info */ int stat_tracking_info (struct branch *branch,int *num_ours,int *num_theirs,const char **upstream_name,enum ahead_behind_flags abf); +int stat_push_info (struct branch *branch,int *num_ours,int *num_theirs, +const char **push_name,enum ahead_behind_flags abf);int format_tracking_info (struct branch *branch,struct strbuf *sb,enum ahead_behind_flags abf);
t/t6300-for-each-ref.sh +12 -1
@@ -392,6 +392,14 @@ test_atom head upstream:track '[ahead 1]' test_atom head upstream:trackshort '>' test_atom head upstream:track,nobracket 'ahead 1' test_atom head upstream:nobracket,track 'ahead 1' + +test_expect_success 'setup for push:track[short]' ' + git update-ref refs/remotes/myfork/master master && + test_commit third +' + +test_atom head upstream:track '[ahead 2]' +test_atom head upstream:trackshort '>' test_atom head push:track '[ahead 1]' test_atom head push:trackshort '>'
@@ -420,8 +428,10 @@ test_expect_success 'Check for invalid refname format' ' test_expect_success 'set up color tests' ' cat >expected.color <<-EOF && $(git rev-parse --short refs/heads/master) <GREEN>master<RESET> + $(git rev-parse --short refs/remotes/myfork/master) <GREEN>myfork/master<RESET> $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET> $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET> + $(git rev-parse --short refs/tags/third) <GREEN>third<RESET> $(git rev-parse --short refs/tags/two) <GREEN>two<RESET> EOF sed "s/<[^>]*>//g" <expected.color >expected.bare &&
@@ -590,10 +600,11 @@ body contents $sig" cat >expected <<EOF -$(git rev-parse refs/tags/bogo) <[email protected]> refs/tags/bogo $(git rev-parse refs/tags/master) <[email protected]> refs/tags/master +$(git rev-parse refs/tags/bogo) <[email protected]> refs/tags/bogo 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 &&
Signature · 1 line
Patched on top of v2.21.0-196-g041f5ea1cf (git version 2.21.0)
Re: [PATCH 1/1] Fix %(push:track) in ref-filter
Quoted 3 lines · Damien Robert
In
ref-filter.c, when processing the atom %(push:track), the ahead/behind values are computed usingstat_tracking_infowhich refers to the upstream branch.
Good catch. I think this has been broken since %(push) was added in 29bc88505f (for-each-ref: accept "%(push)" format, 2015-05-21). I don't actually use the track option, so I never noticed.
Quoted 4 lines
Fix that by introducing a new function
stat_push_infoinremote.c(exported inremote.h), which does the same thing but for the push branch. Factorise the ahead/behind computation ofstat_tracking_infointostat_compare_infoso that it can be reused forstat_push_info.
Makes sense.
Quoted 5 lines
This bug was not detected in
t/t6300-for-each-ref.shbecause in the test for push:track, both the upstream and the push branch were ahead by 1. Change the test so that the upstream branch is ahead by 2 while the push branch is ahead by 1, this allow us to test that %(push:track) refer to the correct branch.
Nice. I wish all patches were this careful about thinking through details like this.
Quoted 7 lines
ref-filter.c +0
-0@@ -1391,8 +1391,11 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname,if (atom->u.remote_ref.option ==RR_REF ) *s =show_ref (&atom->u.remote_ref.refname, refname);
ref-filter.c static void fill_remote_ref_details(struct used_atom *atom, const char *refname, · line 1400
Quoted 10 lines
ref-filter.c +5
-2else if (atom->u.remote_ref.option ==RR_TRACK ) { -if (stat_tracking_info (branch, &num_ours, &num_theirs, -NULL ,AHEAD_BEHIND_FULL ) <0 ) { +if ((atom->u.remote_ref.push ? +stat_push_info (branch, &num_ours, &num_theirs, +NULL ,AHEAD_BEHIND_FULL ) : +stat_tracking_info (branch, &num_ours, &num_theirs, +NULL ,AHEAD_BEHIND_FULL )) <0 ) { *s =xstrdup (msgs.gone); }else if (!num_ours && !num_theirs)
I'm a big fan of the "?" operator, but this ternary-within-an-if might be pushing even my boundaries of taste. :) I wonder if it would be more readable as:
int ret;
if (atom->u.remote_ref.push)
stat_push_info(...); else stat_tracking_info(...); if (ret < 0) ... gone ... else if (!num_ours && !num_theirs) ... etc ...
I'd even be OK with a ternary for assigning "ret". :)
All that said, we would need to do the exact same conditional for ":trackshort", wouldn't we? The tests don't pick it up because the symbol is still ">" for both branches (deja vu!). So it might be worth not just having push be 2 ahead, but have it actually be behind instead (or in addition to).
So since we have to do it twice, maybe that makes it worth factoring out something like:
int stat_remote_ref(struct used_atom *atom, struct branch *branch,
int *num_ours, int *num_theirs)
{
if (atom->u.remote_ref.push)
return stat_push_info(branch, &num_ours, &num_theirs,
NULL, AHEAD_BEHIND_FULL);
else
return stat_tracking_info(branch, &num_ours, &num_theirs,
NULL, AHEAD_BEHIND_FULL);}
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).
ref-filter.c static void fill_remote_ref_details(struct used_atom *atom, const char *refname,
Quoted 6 lines
ref-filter.c +4
-2-int stat_tracking_info (struct branch *branch,int *num_ours,int *num_theirs, -const char **upstream_name,enum ahead_behind_flags abf) + +int stat_compare_info (const char **branch_name,const char **base, +int *num_ours,int *num_theirs, +enum ahead_behind_flags abf)
In the original, we need a pointer-to-pointer for upstream_name, because we return the string as an out-parameter. But here we're just taking two strings as input. We can drop the extra layer of indirection, like the patch below.
Also, since this is an internal helper function for the file, we should mark it as static.
remote.c +7 -7
@@ -1895,23 +1895,23 @@ int resolve_remote_symref(struct ref *ref, struct ref *list)* commits are different. */ -int stat_compare_info (const char **branch_name,const char **base, -int *num_ours,int *num_theirs, -enum ahead_behind_flags abf) +static int stat_compare_info (const char *branch_name,const char *base, +int *num_ours,int *num_theirs, +enum ahead_behind_flags abf) {struct object_id oid;struct commit *ours, *theirs;struct rev_info revs;struct argv_array argv =ARGV_ARRAY_INIT ;/* Cannot stat if what we used to build on no longer exists */ -if (read_ref (*base, &oid)) +if (read_ref (base, &oid))return -1 ; theirs =lookup_commit_reference (the_repository, &oid);if (!theirs)return -1 ; -if (read_ref (*branch_name, &oid)) +if (read_ref (branch_name, &oid))return -1 ; ours =lookup_commit_reference (the_repository, &oid);if (!ours)
@@ -1987,7 +1987,7 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,if (!base)return -1 ; -return stat_compare_info (&(branch->refname), &base, num_ours, num_theirs, abf); +return stat_compare_info (branch->refname, base, num_ours, num_theirs, abf); }/*
@@ -2006,7 +2006,7 @@ int stat_push_info(struct branch *branch, int *num_ours, int *num_theirs,if (!base)return -1 ; -return stat_compare_info (&(branch->refname), &base, num_ours, num_theirs, abf); +return stat_compare_info (branch->refname, base, num_ours, num_theirs, abf); }/*
Of course if you buy my argument above that we should just let ref-filter call into the generic form of the function, then all of that would change. :)
Quoted 1 line
[...]
Other than that, the patch looked quite reasonable. I didn't dig too far into the ripple effects of the test changes, since I think we'll end up changing them again to make sure ":trackshort" is distinct.
Thanks for working on this.
-Peff
Re: [PATCH 1/1] Fix %(push:track) in ref-filter
From Jeff King, Mon 15 Apr 2019 at 18:01:08 (-0400) :
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ if ((atom->u.remote_ref.push ? + stat_push_info(branch, &num_ours, &num_theirs, + NULL, AHEAD_BEHIND_FULL) : + stat_tracking_info(branch, &num_ours, &num_theirs, + NULL, AHEAD_BEHIND_FULL)) < 0) {I'm a big fan of the "?" operator, but this ternary-within-an-if might be pushing even my boundaries of taste. :)
I knew I was pushing the limit of readability a bit here :)
Quoted 2 lines
All that said, we would need to do the exact same conditional for ":trackshort", wouldn't we?
Crap, you are right, I wanted to handle this case too but forgot :-(
Quoted 4 lines
The tests don't pick it up because the
symbol is still ">" for both branches (deja vu!). So it might be worth not just having push be 2 ahead, but have it actually be behind instead (or in addition to).
Done in the new version.
Quoted 4 lines
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.
Quoted 12 lines
Review
Quoted 7 lines
(quoted diff) +4
-2-int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs, - const char **upstream_name, enum ahead_behind_flags abf) + +int stat_compare_info(const char **branch_name, const char **base, + int *num_ours, int *num_theirs, + enum ahead_behind_flags abf)In the original, we need a pointer-to-pointer for
upstream_name, because we return the string as an out-parameter. But here we're just taking two strings as input. We can drop the extra layer of indirection, like the patch below.
Good catch, done.
Quoted 2 lines
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.
Quoted 3 lines
Other than that, the patch looked quite reasonable. I didn't dig too far into the ripple effects of the test changes, since I think we'll end up changing them again to make sure ":trackshort" is distinct.
There are now less impactful than before because the master branch in the test refers to the same commit as before; there is just a new commit for the 'myfork' remote branch.
Quoted 1 line
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 :)
Signature · 35 lines
Damien Robert http://www.normalesup.org/~robert/pro ---- >8 ----- From: Damien Robert <[email protected]> Date: Tue, 16 Apr 2019 14:16:46 +0200 Subject: [v2 PATCH 1/1] Fix %(push:track) in ref-filter In ref-filter.c, when processing the atom %(push:track), the ahead/behind values are computed using `stat_tracking_info` which refers to the upstream branch. Fix that by introducing a new flag `for_push` in `stat_tracking_info` in remote.c, which does the same thing but for the push branch. Update the few callers of `stat_tracking_info` to handle this flag. This ensure that whenever we use this function in the future, we are careful to specify is this should apply to the upstream or the push branch. 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. This change the expected value of some following tests (by introducing new references), so update them too. Signed-off-by: Damien Robert <[email protected]> --- ref-filter.c | 6 ++-- remote.c | 68 ++++++++++++++++++++++++++++------------- remote.h | 3 +- t/t6300-for-each-ref.sh | 14 +++++++-- wt-status.c | 4 +-- 5 files changed, 67 insertions(+), 28 deletions(-)
ref-filter.c +4 -2
@@ -1392,7 +1392,8 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname, *s =show_ref (&atom->u.remote_ref.refname, refname); else if (atom->u.remote_ref.option == RR_TRACK) {if (stat_tracking_info (branch, &num_ours, &num_theirs, -NULL ,AHEAD_BEHIND_FULL ) <0 ) { +NULL , atom->u.remote_ref.push, +AHEAD_BEHIND_FULL ) <0 ) { *s =xstrdup (msgs.gone); }else if (!num_ours && !num_theirs) *s =xstrdup ("" );
@@ -1410,7 +1411,8 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname, } }else if (atom->u.remote_ref.option ==RR_TRACKSHORT ) {if (stat_tracking_info (branch, &num_ours, &num_theirs, -NULL ,AHEAD_BEHIND_FULL ) <0 ) { +NULL , atom->u.remote_ref.push, +AHEAD_BEHIND_FULL ) <0 ) { *s =xstrdup ("" );return ; }
remote.c +47 -21
111 lines not on this page · raw message
remote.h +2 -1
@@ -253,7 +253,8 @@ enum ahead_behind_flags {/* Reporting of tracking info */ int stat_tracking_info (struct branch *branch,int *num_ours,int *num_theirs, -const char **upstream_name,enum ahead_behind_flags abf); +const char **upstream_name,int for_push, +enum ahead_behind_flags abf);int format_tracking_info (struct branch *branch,struct strbuf *sb,enum ahead_behind_flags abf);
t/t6300-for-each-ref.sh +12 -2
@@ -392,8 +392,15 @@ test_atom head upstream:track '[ahead 1]' test_atom head upstream:trackshort '>' test_atom head upstream:track,nobracket 'ahead 1' test_atom head upstream:nobracket,track 'ahead 1' -test_atom head push:track '[ahead 1]' -test_atom head push:trackshort '>' + +test_expect_success 'setup for push:track[short]' ' + test_commit third && + git update-ref refs/remotes/myfork/master master && + git reset master~1 +' + +test_atom head push:track '[behind 1]' +test_atom head push:trackshort '<' test_expect_success 'Check that :track[short] cannot be used with other atoms' ' test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
@@ -420,8 +427,10 @@ test_expect_success 'Check for invalid refname format' ' test_expect_success 'set up color tests' ' cat >expected.color <<-EOF && $(git rev-parse --short refs/heads/master) <GREEN>master<RESET> + $(git rev-parse --short refs/remotes/myfork/master) <GREEN>myfork/master<RESET> $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET> $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET> + $(git rev-parse --short refs/tags/third) <GREEN>third<RESET> $(git rev-parse --short refs/tags/two) <GREEN>two<RESET> EOF sed "s/<[^>]*>//g" <expected.color >expected.bare &&
@@ -594,6 +603,7 @@ $(git rev-parse refs/tags/bogo) <[email protected]> refs/tags/bogo $(git rev-parse refs/tags/master) <[email protected]> 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 &&
wt-status.c +2 -2
@@ -1851,7 +1851,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)color_fprintf (s->fp, branch_color_local,"%s" , branch_name); sti =stat_tracking_info (branch, &num_ours, &num_theirs, &base, - s->ahead_behind_flags); +0 , s->ahead_behind_flags);if (sti <0 ) {if (!base) goto conclude;
@@ -1990,7 +1990,7 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s) branch =branch_get (branch_name); base =NULL ; ab_info =stat_tracking_info (branch, &nr_ahead, &nr_behind, - &base, s->ahead_behind_flags); + &base,0 , s->ahead_behind_flags);if (base) { base =shorten_unambiguous_ref (base,0 );fprintf (s->fp,"# branch.upstream %s%c" , base, eol);
Signature · 1 line
Patched on top of v2.21.0-313-ge35b8cb8e2 (git version 2.21.0)
Re: [PATCH 1/1] Fix %(push:track) in ref-filter
Quoted 3 lines · Damien Robert
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 :)
We often use:
Re: [PATCH 1/1] Fix %(push:track) in ref-filter
In reply to Damien RobertQuoted 9 lines · Damien Robert
Quoted 4 lines
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_infoto accept a 'for_push' flag, and updated the few callers. This means thatstat_compare_infois only used bystat_tracking_infoso 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.
Quoted 6 lines
Quoted 2 lines
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_infodirectly inref_filter.cso I needed to export it inremote.h, and then when I changed the patch I forgot to make it static.
Heh. I wondered if that might have been the reason.
Quoted 5 lines
Quoted 1 line
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:
Quoted 1 line
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?
Quoted 5 lines
This bug was not detected in
t/t6300-for-each-ref.shbecause 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/
Quoted 2 lines
This change the expected value of some following tests (by introducing new references), so update them too.
s/change/&s/
remote.c int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs, · line 1925
Quoted 3 lines
remote.c +1
-1if (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. :)
remote.c int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs, · line 1981
Quoted 4 lines
remote.c +4
-0+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)?
remote.c int format_tracking_info(struct branch *branch, struct strbuf *sb, · line 2006
Quoted 6 lines
remote.c +1
-1@@ -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.
t/t6300-for-each-ref.sh $(git rev-parse refs/tags/bogo) <[email protected]> refs/tags/bogo · line 609
Quoted 10 lines
t/t6300-for-each-ref.sh +1
-0@@ -594,6 +603,7 @@ $(git rev-parse refs/tags/bogo) <[email protected]> refs/tags/bogo $(git rev-parse refs/tags/master) <[email protected]> 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
Damien Robert
Reviewed-by Jeff KingRe: [PATCH 1/1] Fix %(push:track) in ref-filter
From Jeff King, Tue 16 Apr 2019 at 17:48:43 (-0400) :
Quoted 2 lines
The name "
compare_info" is a bit vague. Perhaps "stat_branch_pair" or something would be more descriptive.
Done.
Quoted 1 line
ref-filter: use correct branch for %(push:track)
Done.
Quoted 2 lines
s/refer/&s/
s/change/&s/
Grmf, thanks.
Quoted 2 lines
Is it worth changing "
upstream_name" since it sometimes is now not %(upstream)?
Changed to tracking_name.
Quoted 1 line
Leftover stray whitespace?
Oups.
Quoted 5 lines
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. :)
Here it is:
---- >8 ----
From: Damien Robert <[email protected]>
Date: Tue, 16 Apr 2019 14:16:46 +0200
Subject: [PATCHv3 1/1] ref-filter: use correct branch for %(push:track)
In ref-filter.c, when processing the atom %(push:track), the ahead/behind values are computed using stat_tracking_info which refers to the upstream branch.
Fix that by introducing a new flag for_push in stat_tracking_info in remote.c, which does the same thing but for the push branch. Update the few callers of stat_tracking_info to handle this flag. This ensure that whenever we use this function in the future, we are careful to specify is this should apply to the upstream or the push branch.
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) refers to the correct branch.
This changes the expected value of some following tests (by introducing new references), so update them too.
--- ref-filter.c | 6 ++-- remote.c | 68 ++++++++++++++++++++++++++++------------- remote.h | 3 +- t/t6300-for-each-ref.sh | 13 ++++++-- wt-status.c | 4 +-- 5 files changed, 66 insertions(+), 28 deletions(-)
ref-filter.c +4 -2
@@ -1392,7 +1392,8 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname, *s =show_ref (&atom->u.remote_ref.refname, refname); else if (atom->u.remote_ref.option == RR_TRACK) {if (stat_tracking_info (branch, &num_ours, &num_theirs, -NULL ,AHEAD_BEHIND_FULL ) <0 ) { +NULL , atom->u.remote_ref.push, +AHEAD_BEHIND_FULL ) <0 ) { *s =xstrdup (msgs.gone); }else if (!num_ours && !num_theirs) *s =xstrdup ("" );
@@ -1410,7 +1411,8 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname, } }else if (atom->u.remote_ref.option ==RR_TRACKSHORT ) {if (stat_tracking_info (branch, &num_ours, &num_theirs, -NULL ,AHEAD_BEHIND_FULL ) <0 ) { +NULL , atom->u.remote_ref.push, +AHEAD_BEHIND_FULL ) <0 ) { *s =xstrdup ("" );return ; }
remote.c +47 -21
111 lines not on this page · raw message
remote.h +2 -1
@@ -253,7 +253,8 @@ enum ahead_behind_flags {/* Reporting of tracking info */ int stat_tracking_info (struct branch *branch,int *num_ours,int *num_theirs, -const char **upstream_name,enum ahead_behind_flags abf); +const char **upstream_name,int for_push, +enum ahead_behind_flags abf);int format_tracking_info (struct branch *branch,struct strbuf *sb,enum ahead_behind_flags abf);
t/t6300-for-each-ref.sh +11 -2
@@ -392,8 +392,15 @@ test_atom head upstream:track '[ahead 1]' test_atom head upstream:trackshort '>' test_atom head upstream:track,nobracket 'ahead 1' test_atom head upstream:nobracket,track 'ahead 1' -test_atom head push:track '[ahead 1]' -test_atom head push:trackshort '>' + +test_expect_success 'setup for push:track[short]' ' + test_commit third && + git update-ref refs/remotes/myfork/master master && + git reset master~1 +' + +test_atom head push:track '[behind 1]' +test_atom head push:trackshort '<' test_expect_success 'Check that :track[short] cannot be used with other atoms' ' test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
@@ -420,8 +427,10 @@ test_expect_success 'Check for invalid refname format' ' test_expect_success 'set up color tests' ' cat >expected.color <<-EOF && $(git rev-parse --short refs/heads/master) <GREEN>master<RESET> + $(git rev-parse --short refs/remotes/myfork/master) <GREEN>myfork/master<RESET> $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET> $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET> + $(git rev-parse --short refs/tags/third) <GREEN>third<RESET> $(git rev-parse --short refs/tags/two) <GREEN>two<RESET> EOF sed "s/<[^>]*>//g" <expected.color >expected.bare &&
wt-status.c +2 -2
@@ -1851,7 +1851,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)color_fprintf (s->fp, branch_color_local,"%s" , branch_name); sti =stat_tracking_info (branch, &num_ours, &num_theirs, &base, - s->ahead_behind_flags); +0 , s->ahead_behind_flags);if (sti <0 ) {if (!base) goto conclude;
@@ -1990,7 +1990,7 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s) branch =branch_get (branch_name); base =NULL ; ab_info =stat_tracking_info (branch, &nr_ahead, &nr_behind, - &base, s->ahead_behind_flags); + &base,0 , s->ahead_behind_flags);if (base) { base =shorten_unambiguous_ref (base,0 );fprintf (s->fp,"# branch.upstream %s%c" , base, eol);
Signature · 1 line
Patched on top of v2.21.0-313-ge35b8cb8e2 (git version 2.21.0)
Re: [PATCH 1/1] Fix %(push:track) in ref-filter
Quoted 8 lines · Damien Robert
From: Damien Robert <[email protected]>
Date: Tue, 16 Apr 2019 14:16:46 +0200
Subject: [PATCHv3 1/1] ref-filter: use correct branch for %(push:track)In
ref-filter.c, when processing the atom %(push:track), the ahead/behind values are computed usingstat_tracking_infowhich refers to the upstream branch.
...
Thanks, both. Will queue.