remote: handle negative refspecs in git remote show
PATCH 1/1 remote: handle negative refspecs in git remote show
By default, the git remote show command will query data from remotes to show data about what might be done on a future git fetch. This process currently does not handle negative refspecs. This can be confusing, because the show command will list refs as if they would be fetched. For example if the fetch refspec "^refs/heads/pr/*", it still displays the following:
* remote jdk19
Fetch URL: [email protected]:openjdk/jdk19.git
Push URL: [email protected]:openjdk/jdk19.git
HEAD branch: master
Remote branches:
master tracked
pr/1 new (next fetch will store in remotes/jdk19)
pr/2 new (next fetch will store in remotes/jdk19)
pr/3 new (next fetch will store in remotes/jdk19)
Local ref configured for 'git push':
master pushes to master (fast-forwardable)
Fix this by checking negative refspecs inside of get_ref_states. For each ref which matches a negative refspec, copy it into a "skipped" list and remove it from the fetch map. This allows us to show the following output instead:
* remote jdk19
Fetch URL: [email protected]:openjdk/jdk19.git
Push URL: [email protected]:openjdk/jdk19.git
HEAD branch: master
Remote branches:
master tracked
pr/1 skipped
pr/2 skipped
pr/3 skipped
Local ref configured for 'git push':
master pushes to master (fast-forwardable)
By showing the refs as skipped, it helps clarify that these references won't actually be fetched. Alternatively, we could simply remove them entirely.
Add a new test case to cover this functionality.
--- builtin/remote.c | 28 ++++++++++++++++++++++++++-- remote.c | 2 +- remote.h | 6 ++++++ t/t5505-remote.sh | 27 +++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-)
builtin/remote.c +26 -2
@@ -344,12 +344,13 @@ static void read_branches(void)struct ref_states {struct remote *remote; -struct string_list new_refs, stale, tracked, heads, push; +struct string_list new_refs, skipped, stale, tracked, heads, push;int queried; };#define REF_STATES_INIT { \ .new_refs = STRING_LIST_INIT_DUP, \ + .skipped = STRING_LIST_INIT_DUP, \ .stale = STRING_LIST_INIT_DUP, \ .tracked = STRING_LIST_INIT_DUP, \ .heads = STRING_LIST_INIT_DUP, \
@@ -367,6 +368,24 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *statdie (_ ("Could not get fetch map for refspec %s" ), states->remote->fetch.raw[i]); +/* handle negative refspecs first */ +for (tail = &fetch_map; *tail; ) { + ref = *tail; + +if (omit_name_by_refspec (ref->name, &states->remote->fetch)) { +string_list_append (&states->skipped,abbrev_branch (ref->name)); + +/* Matched a negative refspec, so remove this ref from +* consideration for being a new or tracked ref. +*/ + *tail = ref->next; +free (ref->peer_ref); +free (ref); + }else { + tail = &ref->next; + } + } +for (ref = fetch_map; ref; ref = ref->next) {if (!ref->peer_ref || !ref_exists (ref->peer_ref->name))string_list_append (&states->new_refs,abbrev_branch (ref->name));
@@ -383,6 +402,7 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *statfree_refs (fetch_map);string_list_sort (&states->new_refs); +string_list_sort (&states->skipped);string_list_sort (&states->tracked);string_list_sort (&states->stale);
@@ -941,6 +961,7 @@ static void clear_push_info(void *util, const char *string)static void free_remote_ref_states (struct ref_states *states) {string_list_clear (&states->new_refs,0 ); +string_list_clear (&states->skipped,0 );string_list_clear (&states->stale,1 );string_list_clear (&states->tracked,0 );string_list_clear (&states->heads,0 );
@@ -1033,7 +1054,9 @@ static int show_remote_info_item(struct string_list_item *item, void *cb_data)if (string_list_has_string (&states->new_refs, name)) { fmt =_ (" new (next fetch will store in remotes/%s)" ); arg = states->remote->name; - }else if (string_list_has_string (&states->tracked, name)) + }else if (string_list_has_string (&states->skipped, name)) + arg =_ (" skipped" ); +else if (string_list_has_string (&states->tracked, name)) arg =_ (" tracked" );else if (string_list_has_string (&states->stale, name)) arg =_ (" stale (use 'git remote prune' to remove)" );
@@ -1308,6 +1331,7 @@ static int show(int argc, const char **argv)/* remote branch info */ info.width =0 ;for_each_string_list (&info.states.new_refs, add_remote_to_show_info, &info); +for_each_string_list (&info.states.skipped, add_remote_to_show_info, &info);for_each_string_list (&info.states.tracked, add_remote_to_show_info, &info);for_each_string_list (&info.states.stale, add_remote_to_show_info, &info);if (info.list.nr)
remote.c +1 -1
@@ -804,7 +804,7 @@ static int refspec_match(const struct refspec_item *refspec,return !strcmp (refspec->src, name); } -static int omit_name_by_refspec (const char *name,struct refspec *rs) +int omit_name_by_refspec (const char *name,struct refspec *rs) {int i;
remote.h +6 -0
@@ -247,6 +247,12 @@ int resolve_remote_symref(struct ref *ref, struct ref *list);*/ struct ref *ref_remove_duplicates (struct ref *ref_map); +/* +* Check whether a name matches any negative refspec in rs. Returns 1 if the +* name matches at least one negative refspec, and 0 otherwise. +*/ +int omit_name_by_refspec (const char *name,struct refspec *rs); +/* * Remove all entries in the input list which match any negative refspec in * the refspec list.
t/t5505-remote.sh +27 -0
@@ -302,6 +302,33 @@ test_expect_success 'show' ' ) ' +cat >test/expect <<EOF +* remote origin + Fetch URL: $(pwd)/one + Push URL: $(pwd)/one + HEAD branch: main + Remote branches: + main skipped + side tracked + upstream stale (use 'git remote prune' to remove) + Local branches configured for 'git pull': + ahead merges with remote main + main merges with remote main + Local refs configured for 'git push': + main pushes to main (local out of date) + main pushes to upstream (create) +EOF + +test_expect_success 'show with negative refspecs' ' + test_when_finished "git -C test config --fixed-value --unset remote.origin.fetch ^refs/heads/main" && + ( + cd test && + git config --add remote.origin.fetch ^refs/heads/main && + git remote show origin >output && + test_cmp expect output + ) +' + cat >test/expect <<EOF * remote origin Fetch URL: $(pwd)/one
Signature · 1 line
2.36.1
Quoted 4 lines · Jacob Keller
Fix this by checking negative refspecs inside of
get_ref_states. For each ref which matches a negative refspec, copy it into a "skipped" list and remove it from the fetch map. This allows us to show the following output instead:
Seems sensible.
Quoted 8 lines
builtin/remote.c +8
-0+/* handle negative refspecs first */ +for (tail = &fetch_map; *tail; ) { + ref = *tail; + +if (omit_name_by_refspec (ref->name, &states->remote->fetch)) { +string_list_append (&states->skipped,abbrev_branch (ref->name)); + +/* Matched a negative refspec, so remove this ref from
builtin/remote.c static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat · line 388
Quoted 10 lines
builtin/remote.c +10
-0+* consideration for being a new or tracked ref. +*/ + *tail = ref->next; +free (ref->peer_ref); +free (ref); + }else { + tail = &ref->next; + } + } +
Not being overly familiar with the "git remote show" code, this implementation looks very reasonable to me. If we see a negative refspec, we remove it from the fetch_map list and append it to the skipped list. Otherwise, we increment our pointer, and continue along until we reach the end of the list.
Quoted 20 lines
t/t5505-remote.sh +12
-0@@ -302,6 +302,33 @@ test_expect_success 'show' ' ) ' +cat >test/expect <<EOF +* remote origin + Fetch URL: $(pwd)/one + Push URL: $(pwd)/one + HEAD branch: main + Remote branches: + main skipped + side tracked + upstream stale (use 'git remote prune' to remove) + Local branches configured for 'git pull': + ahead merges with remote main + main merges with remote main
t/t5505-remote.sh test_expect_success 'show' ' · line 326
Quoted 10 lines
t/t5505-remote.sh +10
-0+ Local refs configured for 'git push': + main pushes to main (local out of date) + main pushes to upstream (create) +EOF + +test_expect_success 'show with negative refspecs' ' + test_when_finished "git -C test config --fixed-value --unset remote.origin.fetch ^refs/heads/main" && + ( + cd test && + git config --add remote.origin.fetch ^refs/heads/main &&
Doing "git config --unset" outside of the subshell could be avoided by ditching the subshell altogether, perhaps with something like:
test_config -C test remote.origin.fetch ^refs/heads/main &&
git -C test remote show origin >actual &&
test_cmp test/expect actualThanks,
Taylor
Quoted 68 lines · Taylor Blau
Quoted 4 lines · Jacob Keller
Fix this by checking negative refspecs inside of
get_ref_states. For each ref which matches a negative refspec, copy it into a "skipped" list and remove it from the fetch map. This allows us to show the following output instead:Seems sensible.
Quoted 8 lines
builtin/remote.c +8
-0+/* handle negative refspecs first */ +for (tail = &fetch_map; *tail; ) { + ref = *tail; + +if (omit_name_by_refspec (ref->name, &states->remote->fetch)) { +string_list_append (&states->skipped,abbrev_branch (ref->name)); + +/* Matched a negative refspec, so remove this ref from builtin/remote.c static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat · line 388
Quoted 10 lines
builtin/remote.c +10
-0+* consideration for being a new or tracked ref. +*/ + *tail = ref->next; +free (ref->peer_ref); +free (ref); + }else { + tail = &ref->next; + } + } +Not being overly familiar with the "git remote show" code, this implementation looks very reasonable to me. If we see a negative refspec, we remove it from the
fetch_maplist and append it to the skipped list. Otherwise, we increment our pointer, and continue along until we reach the end of the list.Quoted 20 lines
t/t5505-remote.sh +12
-0@@ -302,6 +302,33 @@ test_expect_success 'show' ' ) ' +cat >test/expect <<EOF +* remote origin + Fetch URL: $(pwd)/one + Push URL: $(pwd)/one + HEAD branch: main + Remote branches: + main skipped + side tracked + upstream stale (use 'git remote prune' to remove) + Local branches configured for 'git pull': + ahead merges with remote main + main merges with remote maint/t5505-remote.sh test_expect_success 'show' ' · line 326
Quoted 10 lines
t/t5505-remote.sh +10
-0+ Local refs configured for 'git push': + main pushes to main (local out of date) + main pushes to upstream (create) +EOF + +test_expect_success 'show with negative refspecs' ' + test_when_finished "git -C test config --fixed-value --unset remote.origin.fetch ^refs/heads/main" && + ( + cd test && + git config --add remote.origin.fetch ^refs/heads/main &&Doing "git config --unset" outside of the subshell could be avoided by ditching the subshell altogether, perhaps with something like:
Quoted 1 line
test_config -C test remote.origin.fetch ^refs/heads/main &&
We need "--add" semantics here which test_config doesn't seem to support at the moment.
Quoted 5 lines
git -C test remote show origin >actual &&
test_cmptest/expect actualThanks,
Taylor
Quoted 6 lines · Jacob Keller
Quoted 6 lines
Quoted 5 lines
t/t5505-remote.sh +5
-0+test_expect_success 'show with negative refspecs' ' + test_when_finished "git -C test config --fixed-value --unset remote.origin.fetch ^refs/heads/main" && + ( + cd test && + git config --add remote.origin.fetch ^refs/heads/main &&
Quoted 7 lines
Quoted 4 lines
Doing "git config --unset" outside of the subshell could be avoided by ditching the subshell altogether, perhaps with something like:
test_config -C test remote.origin.fetch ^refs/heads/main &&We need "--add" semantics here which
test_configdoesn't seem to support at the moment.
Makes sense, thanks for explaining. This patch looks good to me.
Thanks,
Taylor
Quoted 13 lines · Taylor Blau
Quoted 11 lines · Jacob Keller
Quoted 10 lines
t/t5505-remote.sh test_expect_success 'show' ' · line 326
Quoted 5 lines
t/t5505-remote.sh +5
-0+test_expect_success 'show with negative refspecs' ' + test_when_finished "git -C test config --fixed-value --unset remote.origin.fetch ^refs/heads/main" && + ( + cd test && + git config --add remote.origin.fetch ^refs/heads/main &&Doing "git config --unset" outside of the subshell could be avoided by ditching the subshell altogether, perhaps with something like:
test_config -C test remote.origin.fetch ^refs/heads/main &&
Quoted 7 lines
Quoted 2 lines
We need "--add" semantics here which
test_configdoesn't seem to support at the moment.Makes sense, thanks for explaining. This patch looks good to me.
Thanks,
Taylor
I ended up digging into this, and have now additionally added some patches to clean these tests up:
1) drop all the subshells in t5505 where possible
2) modify test_config and test_unconfig to handle options, including --global, --add, and --fixed-value
3) make test_config use --fixed-value with test_unconfig so that only the keys with the exact value are removed
4) use test_config more so that we don't have config values from previous tests kept around
Quoted 25 lines · Taylor Blau
Quoted 4 lines · Jacob Keller
Fix this by checking negative refspecs inside of
get_ref_states. For each ref which matches a negative refspec, copy it into a "skipped" list and remove it from the fetch map. This allows us to show the following output instead:Seems sensible.
Quoted 16 lines
builtin/remote.c +16
-0+/* handle negative refspecs first */ +for (tail = &fetch_map; *tail; ) { + ref = *tail; + +if (omit_name_by_refspec (ref->name, &states->remote->fetch)) { +string_list_append (&states->skipped,abbrev_branch (ref->name)); + +/* Matched a negative refspec, so remove this ref from +* consideration for being a new or tracked ref. +*/ + *tail = ref->next; +free (ref->peer_ref); +free (ref); + }else { + tail = &ref->next; + }
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ } +Not being overly familiar with the "git remote show" code, this implementation looks very reasonable to me. If we see a negative refspec, we remove it from the
fetch_maplist and append it to the skipped list. Otherwise, we increment our pointer, and continue along until we reach the end of the list.
The specific way the loop works is similar to other ref looping code but it feels a little odd to me. Still, it seems to be the right approach overall.
Quoted 6 lines
t/t5505-remote.sh test_expect_success 'show' ' · line 326
Quoted 5 lines
t/t5505-remote.sh +5
-0+test_expect_success 'show with negative refspecs' ' + test_when_finished "git -C test config --fixed-value --unset remote.origin.fetch ^refs/heads/main" && + ( + cd test && + git config --add remote.origin.fetch ^refs/heads/main &&
Quoted 7 lines
Doing "git config --unset" outside of the subshell could be avoided by ditching the subshell altogether, perhaps with something like:
test_config -C test remote.origin.fetch ^refs/heads/main && git -C test remote show origin >actual && test_cmp test/expect actual
I still think that removing the subshell is a good idea here. I'll investigate this.
I also wonder if it would be difficult to enable "--add" semantics for test_config.
Quoted 2 lines
Thanks,
Taylor
Quoted 17 lines · Jacob Keller
Fix this by checking negative refspecs inside of
get_ref_states. For each ref which matches a negative refspec, copy it into a "skipped" list and remove it from the fetch map. This allows us to show the following output instead:* remote jdk19
Fetch URL: [email protected]:openjdk/jdk19.git
Push URL: [email protected]:openjdk/jdk19.git
HEAD branch: master
Remote branches:
master tracked
pr/1 skipped
pr/2 skipped
pr/3 skipped
Local ref configured for 'git push':
master pushes to master (fast-forwardable)
Quoted 3 lines
By showing the refs as skipped, it helps clarify that these references won't actually be fetched. Alternatively, we could simply remove them entirely.
Very sensible.
Quoted 11 lines
builtin/remote.c +7
-0@@ -367,6 +368,24 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *statdie (_ ("Could not get fetch map for refspec %s" ), states->remote->fetch.raw[i]); +/* handle negative refspecs first */ +for (tail = &fetch_map; *tail; ) { + ref = *tail; + +if (omit_name_by_refspec (ref->name, &states->remote->fetch)) { +string_list_append (&states->skipped,abbrev_branch (ref->name)); +
builtin/remote.c static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat · line 387
Quoted 10 lines
builtin/remote.c +10
-0+/* Matched a negative refspec, so remove this ref from +* consideration for being a new or tracked ref. +*/ + *tail = ref->next; +free (ref->peer_ref); +free (ref); + }else { + tail = &ref->next; + } + }
This is somewhat curious. Do we really need to destroy the fetch_map like the above? I know by removing skipped items from the list, the existing loop (below) can stop having to worry about them, but the caller of get_ref_states() may later want to iterate over the full fetch_map for other reasons (even if the current one does not, a future version of the caller may have a reason to do so that we do not know right now yet).
builtin/remote.c static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat · line 391
Quoted 4 lines
builtin/remote.c +1
-0+for (ref = fetch_map; ref; ref = ref->next) {if (!ref->peer_ref || !ref_exists (ref->peer_ref->name))string_list_append (&states->new_refs,abbrev_branch (ref->name));
IOW, is adding a new condition to this existing loop insufficient?
for (ref = fetch_map; ref; ref = ref->next) {- if (!ref->peer_ref || !ref_exists(ref->peer_ref->name))
+ if (omit_name_by_refspec(ref->name, &states->remote->fetch))
+ string_list_append(&states->skipped, abbrev_branch(ref->name));
+ else if (!ref->peer_ref || !ref_exists(ref->peer_ref->name))
string_list_append(&states->new_refs, abbrev_branch(ref->name)); else string_list_append(&states->tracked, abbrev_branch(ref->name)); }
Thanks.
Quoted 49 lines · Junio C Hamano
Quoted 17 lines · Jacob Keller
Fix this by checking negative refspecs inside of
get_ref_states. For each ref which matches a negative refspec, copy it into a "skipped" list and remove it from the fetch map. This allows us to show the following output instead:* remote jdk19
Fetch URL: [email protected]:openjdk/jdk19.git
Push URL: [email protected]:openjdk/jdk19.git
HEAD branch: master
Remote branches:
master tracked
pr/1 skipped
pr/2 skipped
pr/3 skipped
Local ref configured for 'git push':
master pushes to master (fast-forwardable)Quoted 3 lines
By showing the refs as skipped, it helps clarify that these references won't actually be fetched. Alternatively, we could simply remove them entirely.
Very sensible.
Quoted 11 lines
builtin/remote.c +7
-0@@ -367,6 +368,24 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *statdie (_ ("Could not get fetch map for refspec %s" ), states->remote->fetch.raw[i]); +/* handle negative refspecs first */ +for (tail = &fetch_map; *tail; ) { + ref = *tail; + +if (omit_name_by_refspec (ref->name, &states->remote->fetch)) { +string_list_append (&states->skipped,abbrev_branch (ref->name)); +builtin/remote.c static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat · line 387
Quoted 10 lines
builtin/remote.c +10
-0+/* Matched a negative refspec, so remove this ref from +* consideration for being a new or tracked ref. +*/ + *tail = ref->next; +free (ref->peer_ref); +free (ref); + }else { + tail = &ref->next; + } + }
Quoted 8 lines
This is somewhat curious. Do we really need to destroy the
fetch_maplike the above? I know by removing skipped items from the list, the existing loop (below) can stop having to worry about them, but the caller ofget_ref_states()may later want to iterate over the fullfetch_mapfor other reasons (even if the current one does not, a future version of the caller may have a reason to do so that we do not know right now yet).
Good point. I'll fix this. I think we can just move the omit_name_by_refspec into the other loop.
Quoted 7 lines
builtin/remote.c static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat · line 391
Quoted 4 lines
builtin/remote.c +1
-0+for (ref = fetch_map; ref; ref = ref->next) {if (!ref->peer_ref || !ref_exists (ref->peer_ref->name))string_list_append (&states->new_refs,abbrev_branch (ref->name));IOW, is adding a new condition to this existing loop insufficient?
The tricky part here is that we don't have a simple check, and we're currently iterating over all of the refspecs each time. But we have to do that regardless so I think this makes sense. Will fix.
Quoted 12 lines
for (ref = fetch_map; ref; ref = ref->next) {(quoted diff) +3
-1- if (!ref->peer_ref || !ref_exists(ref->peer_ref->name)) + if (omit_name_by_refspec(ref->name, &states->remote->fetch)) + string_list_append(&states->skipped, abbrev_branch(ref->name)); + else if (!ref->peer_ref || !ref_exists(ref->peer_ref->name)) string_list_append(&states->new_refs, abbrev_branch(ref->name)); else string_list_append(&states->tracked, abbrev_branch(ref->name)); }Thanks.
Quoted 17 lines · Jacob Keller
Quoted 8 lines
This is somewhat curious. Do we really need to destroy the
fetch_maplike the above? I know by removing skipped items from the list, the existing loop (below) can stop having to worry about them, but the caller ofget_ref_states()may later want to iterate over the fullfetch_mapfor other reasons (even if the current one does not, a future version of the caller may have a reason to do so that we do not know right now yet).Good point. I'll fix this. I think we can just move the
omit_name_by_refspecinto the other loop.Quoted 5 lines
Quoted 4 lines
+
for (ref = fetch_map; ref; ref = ref->next) { if (!ref->peer_ref || !ref_exists(ref->peer_ref->name)) string_list_append(&states->new_refs, abbrev_branch(ref->name));
Quoted 6 lines
Quoted 2 lines
IOW, is adding a new condition to this existing loop insufficient?
The tricky part here is that we don't have a simple check, and we're currently iterating over all of the refspecs each time. But we have to do that regardless so I think this makes sense. Will fix.
Another thing that worries me is that get_stale_heads() will not see the filtered refs with your original implementation, because you cull them from the fetch_map in the extra loop upfront.
I do not know offhand what its effect would be, but it probably is worth testing. In your original scenario, if we locally have refs/remotes/jdk19/old and refs/remotes/jdk19/pr/1 (perhaps obtained before we configured ^refs/pr/* negative refspec), we'd want to see that pr/1 exists here but will not be updated.
* remote jdk19
Fetch URL: [email protected]:openjdk/jdk19.git
Push URL: [email protected]:openjdk/jdk19.git
HEAD branch: master
Remote branches:
master tracked
old stale
pr/1 stale
pr/2 skipped
pr/3 skipped
Local ref configured for 'git push':
master pushes to master (fast-forwardable)
Quoted 23 lines · Junio C Hamano
Quoted 20 lines · Jacob Keller
Quoted 8 lines
This is somewhat curious. Do we really need to destroy the
fetch_maplike the above? I know by removing skipped items from the list, the existing loop (below) can stop having to worry about them, but the caller ofget_ref_states()may later want to iterate over the fullfetch_mapfor other reasons (even if the current one does not, a future version of the caller may have a reason to do so that we do not know right now yet).Good point. I'll fix this. I think we can just move the
omit_name_by_refspecinto the other loop.Quoted 7 lines
Quoted 4 lines
+
for (ref = fetch_map; ref; ref = ref->next) { if (!ref->peer_ref || !ref_exists(ref->peer_ref->name)) string_list_append(&states->new_refs, abbrev_branch(ref->name));IOW, is adding a new condition to this existing loop insufficient?
Quoted 8 lines
Quoted 3 lines
The tricky part here is that we don't have a simple check, and we're currently iterating over all of the refspecs each time. But we have to do that regardless so I think this makes sense. Will fix.
Another thing that worries me is that
get_stale_heads()will not see the filtered refs with your original implementation, because you cull them from thefetch_mapin the extra loop upfront.
I think the new implementation fixed this, but I'll see about adding a test!
Quoted 6 lines
I do not know offhand what its effect would be, but it probably is worth testing. In your original scenario, if we locally have refs/remotes/jdk19/old and refs/remotes/jdk19/pr/1 (perhaps obtained before we configured ^refs/pr/* negative refspec), we'd want to see that pr/1 exists here but will not be updated.
Yea, I will see if I can check that.
Quoted 12 lines
* remote jdk19
Fetch URL: [email protected]:openjdk/jdk19.git
Push URL: [email protected]:openjdk/jdk19.git
HEAD branch: master
Remote branches:
master tracked
old stale
pr/1 stale
pr/2 skipped
pr/3 skipped
Local ref configured for 'git push':
master pushes to master (fast-forwardable)
Quoted 36 lines · Jacob Keller
Quoted 23 lines · Junio C Hamano
Quoted 20 lines · Jacob Keller
Quoted 8 lines
This is somewhat curious. Do we really need to destroy the
fetch_maplike the above? I know by removing skipped items from the list, the existing loop (below) can stop having to worry about them, but the caller ofget_ref_states()may later want to iterate over the fullfetch_mapfor other reasons (even if the current one does not, a future version of the caller may have a reason to do so that we do not know right now yet).Good point. I'll fix this. I think we can just move the
omit_name_by_refspecinto the other loop.Quoted 7 lines
Quoted 4 lines
+
for (ref = fetch_map; ref; ref = ref->next) { if (!ref->peer_ref || !ref_exists(ref->peer_ref->name)) string_list_append(&states->new_refs, abbrev_branch(ref->name));IOW, is adding a new condition to this existing loop insufficient?
Quoted 8 lines
Quoted 3 lines
The tricky part here is that we don't have a simple check, and we're currently iterating over all of the refspecs each time. But we have to do that regardless so I think this makes sense. Will fix.
Another thing that worries me is that
get_stale_heads()will not see the filtered refs with your original implementation, because you cull them from thefetch_mapin the extra loop upfront.I think the new implementation fixed this, but I'll see about adding a test!
Quoted 9 lines
Quoted 6 lines
I do not know offhand what its effect would be, but it probably is worth testing. In your original scenario, if we locally have refs/remotes/jdk19/old and refs/remotes/jdk19/pr/1 (perhaps obtained before we configured ^refs/pr/* negative refspec), we'd want to see that pr/1 exists here but will not be updated.
Yea, I will see if I can check that.
Ok so this raises another issue: get_stale_heads currently never treats a refname as stale if it matches a negative refspec. The function first queries the name against all refspecs via query_refspecs_mutiple. It only considers a ref stale if it matches at least one refspec but no longer exists in the remote.
The problem is that query_refspecs_multple returns no matches if the refname matches any negative refspec. Thus, all refs matching a negative refspec will be ignored by get_stale_heads.
The query_refspecs_multiple is only used by get_stale_heads_cb, so we could change its implementation possibly, but that would make it not quite match the name. I'll try to think of a better solution.
Thanks,
Jake
Quoted 12 lines
Quoted 12 lines
* remote jdk19
Fetch URL: [email protected]:openjdk/jdk19.git
Push URL: [email protected]:openjdk/jdk19.git
HEAD branch: master
Remote branches:
master tracked
old stale
pr/1 stale
pr/2 skipped
pr/3 skipped
Local ref configured for 'git push':
master pushes to master (fast-forwardable)