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

Re: [RFC 3/3] refspec: add support for negative refspecs

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 17, 2020, 23:43 UTC
Message-ID
<xmqq5z9gzvmb.fsf@gitster.c.googlers.com>
In-Reply-To
<20200815002509.2467645-3-jacob.e.keller@intel.com>
Jacob Keller <jacob.e.keller@intel.com> writes:
Show 5 quoted lines
> Refspecs today are commutative, meaning that order doesn't expressly
> matter. Rather than forcing an implied order, negative refspecs will
> always be applied last. That is, in order to match, a ref must match at
> least one positive refspec, and match none of the negative refspecs.
> This is similar to how negative pathspecs work.

Yes, enumerate what positive ones match and then exclude what negative ones match from the result is a time-tested pattern our users know how things work.

Show 8 quoted lines
> @@ -530,6 +530,9 @@ static struct ref *get_ref_map(struct remote *remote,
>  		tail = &rm->next;
>  	}
>  
> +	/* apply any negative refspecs now to prune the list of refs */
> +	ref_map = apply_negative_refspecs(ref_map, rs);
> +
>  	ref_map = ref_remove_duplicates(ref_map);

How was the ordering here decided? Should it result the same set if negative ones are excluded after duplicates are removed?

Show 6 quoted lines
> @@ -1441,6 +1445,8 @@ int match_push_refs(struct ref *src, struct ref **dst,
>  		string_list_clear(&src_ref_index, 0);
>  	}
>  
> +	*dst = apply_negative_refspecs(*dst, rs);
> +

The block of code whose tail is shown in the pre-context has prepared "delete these refs because we no longer have them" to the other side under MATCH_REFS_PRUNE but that was done based on the *dst list before we applied the negative refspec. Is the ordering of these two correct, or should we filter the dst list with negative ones and use the resulting one in pruning operation?

Show 9 quoted lines
> +	if (item->negative) {
> +		struct object_id unused;
> +
> +		/*
> +		 * Negative refspecs only have a LHS, which indicates a ref
> +		 * (or pattern of refs) to exclude from other matches. This
> +		 * can either be a simple ref, a glob pattern, or even an
> +		 * exact sha1 match.
> +		 */

"a ref (or pattern of refs)" is clarified with the next sentence anyway, so let's not say it, e.g.

	... only have a LHS, which indicates what to exclude from
	other matches.
Previous: Jacob KellerNext: Jacob Keller
Message 7 of 20 in “[RFC 1/3] refspec: fix documentation referring to refspec_item”
  1. Jacob KellerAug 15, 2020
  2. 2/3 refspec: make sure stack refspec_item variables are zeroedJacob Keller, Aug 15, 2020
  3. Junio C HamanoAug 17, 2020
  4. Jacob KellerAug 17, 2020
  5. 3/3 refspec: add support for negative refspecsJacob Keller, Aug 15, 2020
  6. Jacob KellerAug 17, 2020
  7. Junio C HamanoAug 17, 2020
  8. Jacob KellerAug 18, 2020
  9. Jeff KingAug 18, 2020
  10. Jacob KellerAug 20, 2020
  11. Jeff KingAug 21, 2020
  12. Junio C HamanoAug 21, 2020
  13. Jacob KellerAug 21, 2020
  14. Jacob KellerAug 21, 2020
  15. Jacob KellerAug 21, 2020
  16. Jacob KellerAug 21, 2020
  17. Jeff KingAug 21, 2020
  18. Junio C HamanoAug 17, 2020
  19. Jacob KellerAug 21, 2020
  20. Junio C HamanoAug 21, 2020

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.