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

Re: [PATCH v3 4/4] pack-refs: teach pack-refs --include option

From
Junio C Hamano <gitster@pobox.com>
Date
May 11, 2023, 20:06 UTC
Message-ID
<xmqq8rduvdj0.fsf@gitster.g>
In-Reply-To
<b2f3b98cd2461a25ab708adbcd8a95f5e2b18e5e.1683828635.git.gitgitgadget@gmail.com>
"John Cai via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 13 quoted lines
> @@ -1198,7 +1191,13 @@ static int should_pack_ref(const char *refname,
>  	if (!ref_resolves_to_object(refname, the_repository, oid, ref_flags))
>  		return 0;
>  
> -	return 1;
> +	if (opts->visibility && ref_excluded(opts->visibility, refname))
> +		return 0;
> +
> +	if (opts->visibility && ref_included(opts->visibility, refname))
> +		return 1;
> +
> +	return 0;
>  }

When the user did not say --exclude or --include, can we not have opts->visibility? IOW, can opts->visiblity be NULL?

Even if it can be NULL, shouldn't we be defaulting to "pack", as we rejected refs to be excluded already?

Show 12 quoted lines
> @@ -33,5 +38,14 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
>  	for_each_string_list_item(item, &option_excluded_refs)
>  		add_ref_exclusion(pack_refs_opts.visibility, item->string);
>  
> +	for_each_string_list_item(item, &option_included_refs)
> +		add_ref_inclusion(pack_refs_opts.visibility, item->string);
> +
> +	if (pack_refs_opts.flags & PACK_REFS_ALL)
> +		add_ref_inclusion(pack_refs_opts.visibility, "*");
> +
> +	if (!pack_refs_opts.visibility->included_refs.nr)
> +		add_ref_inclusion(pack_refs_opts.visibility, "refs/tags/*");

Given the above code, I think visibility is always non-NULL, and the inclusion list has at least one element. So the above "what should be the default?" question is theoretical. But it would be nicer if we do not check opts->visibility there. By writing

	if (opts->visibility && ref_included(opts->visibility, refname))
		return 1;

you are saying "if visibility is defined and it is included, say YES", and logically it follows that, if we did not return true from here, we do not know if the end-user supplied inclusion list did not match (i.e. ref_included() said no), or we skipped the check because the end-user did not supply the visibility rule. It is easy to mistake that the next statement after this, i.e. "return 0;", is the default action when the end-user did not give any rule.

But that is not what is going on. Because visibility is always given,

The last part would become
	if (ref_included(opts->visibility, refname))
		return 1;
	return 0;

and the "return 0" is no longer confusing. If inclusion check says yes, the result is "to include", otherwise the result is "not to include". Even shorter, we could say

	return !ref_excluded(opts->visibility, refname) &&
		ref_included(opts->visibility, refname) &&

which we can trivially read the design decision: exclude list has priority, and include list is consulted only after exclude list does not ban it.

Thanks.
Previous: John Cai via GitGitGadgetNext: John Cai
Message 23 of 29 in “pack-refs: teach --exclude option to exclude refs from being packed”
  1. pack-refs: teach --exclude option to exclude refs from being packedJohn Cai via GitGitGadget, May 4, 2023
  2. Junio C HamanoMay 4, 2023
  3. John CaiMay 4, 2023
  4. 0/3 pack-refs: Teach --exclude option to exclude refs from being packedJohn Cai via GitGitGadget, May 9, 2023
  5. 1/3 docs: clarify git-pack-refs --all will pack all refsJohn Cai via GitGitGadget, May 9, 2023
  6. 2/3 pack-refs: teach --exclude option to exclude refs from being packedJohn Cai via GitGitGadget, May 9, 2023
  7. Junio C HamanoMay 9, 2023
  8. 3/3 pack-refs: teach pack-refs --include optionJohn Cai via GitGitGadget, May 9, 2023
  9. Junio C HamanoMay 9, 2023
  10. John CaiMay 10, 2023
  11. 0/4 pack-refs: allow users control over which refs to packJohn Cai via GitGitGadget, May 11, 2023
  12. 1/4 docs: clarify git-pack-refs --all will pack all refsJohn Cai via GitGitGadget, May 11, 2023
  13. Taylor BlauMay 11, 2023
  14. 2/4 pack-refs: teach --exclude option to exclude refs from being packedJohn Cai via GitGitGadget, May 11, 2023
  15. Junio C HamanoMay 11, 2023
  16. Taylor BlauMay 12, 2023
  17. John CaiMay 12, 2023
  18. John CaiMay 12, 2023
  19. 3/4 revision: modify ref_exclusions to handle inclusionsJohn Cai via GitGitGadget, May 11, 2023
  20. Junio C HamanoMay 11, 2023
  21. John CaiMay 12, 2023
  22. 4/4 pack-refs: teach pack-refs --include optionJohn Cai via GitGitGadget, May 11, 2023
  23. Junio C HamanoMay 11, 2023
  24. John CaiMay 12, 2023
  25. John CaiMay 12, 2023
  26. 0/3 pack-refs: allow users control over which refs to packJohn Cai via GitGitGadget, May 12, 2023
  27. 2/3 pack-refs: teach --exclude option to exclude refs from being packedJohn Cai via GitGitGadget, May 12, 2023
  28. 3/3 pack-refs: teach pack-refs --include optionJohn Cai via GitGitGadget, May 12, 2023
  29. 1/3 docs: clarify git-pack-refs --all will pack all refsJohn Cai via GitGitGadget, May 12, 2023

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.