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

Re: [PATCH v2 3/3] repository: create read_replace_refs setting

From
Victoria Dye <vdye@github.com>
Date
Jun 5, 2023, 19:32 UTC
Message-ID
<f8094f2d-fbf7-3379-a630-781eb09cce64@github.com>
In-Reply-To
<4c7dbeb8c6dd6ab4c1903196967d5e0906a293c2.1685716158.git.gitgitgadget@gmail.com>
Derrick Stolee via GitGitGadget wrote:
Show 10 quoted lines
> diff --git a/repository.h b/repository.h
> index c42f7ab6bdc..5315e0852e3 100644
> --- a/repository.h
> +++ b/repository.h
> @@ -39,6 +39,15 @@ struct repo_settings {
>  	int pack_read_reverse_index;
>  	int pack_use_bitmap_boundary_traversal;
>  
> +	/*
> +	 * Has this repository have core.useReplaceRefs=true (on by
s/Has/Does(?)

It's not a huge deal, but if you were planning to re-roll anyway due to [1], this should be easy enough to include.

[1] https://lore.kernel.org/git/a1967c58-48c5-6ae0-f60a-2d8c107f8f66@web.de/
Show 44 quoted lines
> +	 * default)? This provides a repository-scoped version of this
> +	 * config, though it could be disabled process-wide via some Git
> +	 * builtins or the --no-replace-objects option. See
> +	 * replace_refs_enabled() for more details.
> +	 */
> +	int read_replace_refs;
> +
>  	struct fsmonitor_settings *fsmonitor; /* lazily loaded */
>  
>  	int index_version;
> diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh
> index 8143817b19e..d37c83b4640 100755
> --- a/t/t7814-grep-recurse-submodules.sh
> +++ b/t/t7814-grep-recurse-submodules.sh
> @@ -594,4 +594,44 @@ test_expect_success 'grep partially-cloned submodule' '
>  	)
>  '
>  
> +test_expect_success 'check scope of core.useReplaceRefs' '
> +	git init base &&
> +	git init base/sub &&
> +
> +	echo A >base/a &&
> +	echo B >base/b &&
> +	echo C >base/sub/c &&
> +	echo D >base/sub/d &&
> +
> +	git -C base/sub add c d &&
> +	git -C base/sub commit -m "Add files" &&
> +
> +	git -C base submodule add ./sub &&
> +	git -C base add a b sub &&
> +	git -C base commit -m "Add files and submodule" &&
> +
> +	A=$(git -C base rev-parse HEAD:a) &&
> +	B=$(git -C base rev-parse HEAD:b) &&
> +	C=$(git -C base/sub rev-parse HEAD:c) &&
> +	D=$(git -C base/sub rev-parse HEAD:d) &&
> +
> +	git -C base replace $A $B &&
> +	git -C base/sub replace $C $D &&
> +
> +	test_must_fail git -C base grep --cached --recurse-submodules A &&
> +	test_must_fail git -C base grep --cached --recurse-submodules C &&

First, we verify that replace refs are enabled on both the superproject and submodule by default (if they are, 'a' has been replaced with 'b' and 'c' has been replaced with 'd')...

> +
> +	git -C base config core.useReplaceRefs false &&
> +	git -C base grep --recurse-submodules A &&
> +	test_must_fail git -C base grep --cached --recurse-submodules C &&

...then, if replace refs are disabled in the superproject (but not the submodule), 'b' no longer replaces 'a' but 'd' still replaces 'c'...

> +
> +	git -C base/sub config core.useReplaceRefs false &&
> +	git -C base grep --cached --recurse-submodules A &&
> +	git -C base grep --cached --recurse-submodules C &&

...but once replace refs are disabled in the submodule, 'd' no longer replaces 'c', and 'b' still doesn't replace 'a'...

> +
> +	git -C base config --unset core.useReplaceRefs &&
> +	test_must_fail git -C base grep --cached --recurse-submodules A &&
> +	git -C base grep --cached --recurse-submodules C

...and, finally, if we restore the default state in the superproject (replace refs enabled) but not the submodule, 'b' once again replaces 'a', but 'd' still doesn't replace 'c'.

Thanks for adding this test! It clearly and thoroughly exercises the updated config behavior.

> +'
> +
>  test_done
Previous: Derrick Stolee via GitGitGadgetNext: Elijah Newren
Message 25 of 32 in “Create stronger guard rails on replace refs”
  1. 0/3 Create stronger guard rails on replace refsDerrick Stolee via GitGitGadget, May 26, 2023
  2. 1/3 repository: create disable_replace_refs()Derrick Stolee via GitGitGadget, May 26, 2023
  3. Elijah NewrenMay 31, 2023
  4. Derrick StoleeMay 31, 2023
  5. Jeff KingJun 1, 2023
  6. Junio C HamanoJun 3, 2023
  7. Jeff KingJun 4, 2023
  8. Junio C HamanoJun 1, 2023
  9. Victoria DyeJun 1, 2023
  10. 2/3 replace-objects: create wrapper around settingDerrick Stolee via GitGitGadget, May 26, 2023
  11. Victoria DyeJun 1, 2023
  12. Derrick StoleeJun 1, 2023
  13. Elijah NewrenJun 3, 2023
  14. Derrick StoleeJun 5, 2023
  15. 3/3 repository: create read_replace_refs settingDerrick Stolee via GitGitGadget, May 26, 2023
  16. Victoria DyeJun 1, 2023
  17. Derrick StoleeJun 1, 2023
  18. Elijah NewrenMay 31, 2023
  19. 0/3 Create stronger guard rails on replace refsDerrick Stolee via GitGitGadget, Jun 2, 2023
  20. 1/3 repository: create disable_replace_refs()Derrick Stolee via GitGitGadget, Jun 2, 2023
  21. 2/3 replace-objects: create wrapper around settingDerrick Stolee via GitGitGadget, Jun 2, 2023
  22. René ScharfeJun 3, 2023
  23. Derrick StoleeJun 5, 2023
  24. 3/3 repository: create read_replace_refs settingDerrick Stolee via GitGitGadget, Jun 2, 2023
  25. Victoria DyeJun 5, 2023
  26. Elijah NewrenJun 3, 2023
  27. 0/3 Create stronger guard rails on replace refsDerrick Stolee via GitGitGadget, Jun 6, 2023
  28. 1/3 repository: create disable_replace_refs()Derrick Stolee via GitGitGadget, Jun 6, 2023
  29. 2/3 replace-objects: create wrapper around settingDerrick Stolee via GitGitGadget, Jun 6, 2023
  30. 3/3 repository: create read_replace_refs settingDerrick Stolee via GitGitGadget, Jun 6, 2023
  31. Victoria DyeJun 6, 2023
  32. Junio C HamanoJun 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.