git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] remote: handle negative refspecs in git remote show

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 15, 2022, 21:44 UTC
Message-ID
<xmqqzgidy52c.fsf@gitster.g>
In-Reply-To
<20220614003251.16765-1-jacob.e.keller@intel.com>
Jacob Keller <jacob.keller@gmail.com> writes:
Show 20 quoted lines
> 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: git@github.com:openjdk/jdk19.git
>     Push  URL: git@github.com: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.
Very sensible.
Show 21 quoted lines
> @@ -367,6 +368,24 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
>  			die(_("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;
> +		}
> +	}

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).

> +
>  	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.
Previous: Jacob KellerNext: Jacob Keller
Message 7 of 11 in “remote: handle negative refspecs in git remote show”
  1. remote: handle negative refspecs in git remote showJacob Keller, Jun 14, 2022
  2. Taylor BlauJun 14, 2022
  3. Jacob KellerJun 14, 2022
  4. Taylor BlauJun 14, 2022
  5. Jacob KellerJun 16, 2022
  6. Jacob KellerJun 14, 2022
  7. Junio C HamanoJun 15, 2022
  8. Jacob KellerJun 16, 2022
  9. Junio C HamanoJun 16, 2022
  10. Jacob KellerJun 16, 2022
  11. Jacob KellerJun 16, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.