Skip to contentSkip to conversation

write-tree: integrate with sparse index

RFC PATCH Superseded Shuqi Liang 3 participants 20 messages Apr 2, 2023 – May 8, 2023

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 write-tree: integrate with sparse index

Update 'git write-tree' to allow using the sparse-index in memory without expanding to a full one.

The recursive algorithm for update_one() was already updated in 2de37c5 (cache-tree: integrate with sparse directory entries, 2021-03-03) to handle sparse directory entries in the index. Hence we can just set the requires-full-index to false for "write-tree".

The p2000 tests demonstrate a ~96% execution time reduction for 'git write-tree' using a sparse index:

Test before after
-----------------------------------------------------------------

2000.78: git write-tree (full-v3)              0.34    0.33 -2.9%
2000.79: git write-tree (full-v4)              0.32    0.30 -6.3%
2000.80: git write-tree (sparse-v3)            0.47    0.02 -95.8%
2000.81: git write-tree (sparse-v4)            0.45    0.02 -95.6%
---
 builtin/write-tree.c                     |  4 ++++
 t/perf/p2000-sparse-operations.sh        |  1 +
 t/t1092-sparse-checkout-compatibility.sh | 28 ++++++++++++++++++++++++
 3 files changed, 33 insertions(+)
builtin/write-tree.c +4 -0
index 45d61707e7..28c45b4301 100644
@@ -35,6 +35,10 @@ int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
 	};
 
 	git_config(git_default_config, NULL);
+	
+	prepare_repo_settings(the_repository);
+	the_repository->settings.command_requires_full_index = 0;
+
 	argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
 			     write_tree_usage, 0);
 
t/perf/p2000-sparse-operations.sh +1 -0
index 3242cfe91a..9924adfc26 100755
@@ -125,5 +125,6 @@ test_perf_on_all git checkout-index -f --all
 test_perf_on_all git update-index --add --remove $SPARSE_CONE/a
 test_perf_on_all "git rm -f $SPARSE_CONE/a && git checkout HEAD -- $SPARSE_CONE/a"
 test_perf_on_all git grep --cached --sparse bogus -- "f2/f1/f1/*"
+test_perf_on_all git write-tree 
 
 test_done
t/t1092-sparse-checkout-compatibility.sh +28 -0
index 801919009e..3b8191b390 100755
@@ -2055,4 +2055,32 @@ test_expect_success 'grep sparse directory within submodules' '
 	test_cmp actual expect
 '
 
+test_expect_success 'write-tree on all' '
+	init_repos &&
+
+	write_script edit-contents <<-\EOF &&
+	echo text >>"$1"
+	EOF
+
+	run_on_all ../edit-contents deep/a &&
+	run_on_all git update-index deep/a &&
+	test_all_match git write-tree &&
+
+	run_on_all mkdir -p folder1 &&
+	run_on_all cp a folder1/a &&
+	run_on_all ../edit-contents folder1/a &&
+	run_on_all git update-index folder1/a &&
+	test_all_match git write-tree
+'
+
+test_expect_success 'sparse-index is not expanded: write-tree' '
+	init_repos &&
+
+	ensure_not_expanded write-tree &&
+
+	echo "test1" >>sparse-index/a &&
+	git -C sparse-index update-index a &&
+	ensure_not_expanded write-tree 
+'
+
 test_done
Signature · 1 line
2.39.0
#1 lore raw
Quoted 18 lines · Shuqi Liang

Update 'git write-tree' to allow using the sparse-index in memory without expanding to a full one.

The recursive algorithm for update_one() was already updated in 2de37c5 (cache-tree: integrate with sparse directory entries, 2021-03-03) to handle sparse directory entries in the index. Hence we can just set the requires-full-index to false for "write-tree".

The p2000 tests demonstrate a ~96% execution time reduction for 'git write-tree' using a sparse index:

Test before after
-----------------------------------------------------------------

2000.78: git write-tree (full-v3)              0.34    0.33 -2.9%
2000.79: git write-tree (full-v4)              0.32    0.30 -6.3%
2000.80: git write-tree (sparse-v3)            0.47    0.02 -95.8%
2000.81: git write-tree (sparse-v4)            0.45    0.02 -95.6%
Quoted 6 lines
---
 builtin/write-tree.c                     |  4 ++++
 t/perf/p2000-sparse-operations.sh        |  1 +
 t/t1092-sparse-checkout-compatibility.sh | 28 ++++++++++++++++++++++++
 3 files changed, 33 insertions(+)

Has the test suite been exercised with this patch? It seems to break at least t0012

#2 lore raw
Quoted 3 lines · Junio C Hamano

Has the test suite been exercised with this patch? It seems to break at least t0012

Hi Junio

I commented out the 'test_perf_on_all git grep --cached bogus -- "f2/f1/f1/*"' before
running 'p2000-sparse-operations.sh'. I did this because I found that with its presence,
even without adding any code, the tests wouldn't pass. After commenting it out, everything worked well. (In the patch I submitted above I did not commented it out )

Thanks
Shuqi

#3 lore raw
Quoted 9 lines · Shuqi Liang
Quoted 3 lines

Has the test suite been exercised with this patch? It seems to break at least t0012

Hi Junio

I commented out the 'test_perf_on_all git grep --cached bogus -- "f2/f1/f1/*"' before
running 'p2000-sparse-operations.sh'.

Sorry, but I do not see why you are bringing up p2000 performance measurement script here.

#4 lore raw

PATCH v2 1/1 write-tree: integrate with sparse index

In reply to Shuqi Liang

Update 'git write-tree' to allow using the sparse-index in memory without expanding to a full one.

The recursive algorithm for update_one() was already updated in 2de37c5 (cache-tree: integrate with sparse directory entries, 2021-03-03) to handle sparse directory entries in the index. Hence we can just set the requires-full-index to false for "write-tree".

The p2000 tests demonstrate a ~96% execution time reduction for 'git write-tree' using a sparse index:

Test before after
-----------------------------------------------------------------

2000.78: git write-tree (full-v3)              0.34    0.33 -2.9%
2000.79: git write-tree (full-v4)              0.32    0.30 -6.3%
2000.80: git write-tree (sparse-v3)            0.47    0.02 -95.8%
2000.81: git write-tree (sparse-v4)            0.45    0.02 -95.6%

---

* change the position of "settings.command_requires_full_index = 0"

Range-diff against v1:
1: d8a9ccd0b3 ! 1: 8873c79759 write-tree: integrate with sparse index

    @@ Commit message
     
      ## builtin/write-tree.c ##
     @@ builtin/write-tree.c: int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
    - 	};
    - 
    - 	git_config(git_default_config, NULL);
    -+	
    -+	prepare_repo_settings(the_repository);
    -+	the_repository->settings.command_requires_full_index = 0;
    -+
      	argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
      			     write_tree_usage, 0);
      
    ++	prepare_repo_settings(the_repository);
    ++	the_repository->settings.command_requires_full_index = 0;
    ++	
    + 	ret = write_cache_as_tree(&oid, flags, tree_prefix);
    + 	switch (ret) {
    + 	case 0:
     
      ## t/perf/p2000-sparse-operations.sh ##
     @@ t/perf/p2000-sparse-operations.sh: test_perf_on_all git checkout-index -f --all
 builtin/write-tree.c                     |  3 +++
 t/perf/p2000-sparse-operations.sh        |  1 +
 t/t1092-sparse-checkout-compatibility.sh | 28 ++++++++++++++++++++++++
 3 files changed, 32 insertions(+)
builtin/write-tree.c +3 -0
index 45d61707e7..4492da0912 100644
@@ -38,6 +38,9 @@ int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
 	argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
 			     write_tree_usage, 0);
 
+	prepare_repo_settings(the_repository);
+	the_repository->settings.command_requires_full_index = 0;
+	
 	ret = write_cache_as_tree(&oid, flags, tree_prefix);
 	switch (ret) {
 	case 0:
t/perf/p2000-sparse-operations.sh +1 -0
index 3242cfe91a..9924adfc26 100755
@@ -125,5 +125,6 @@ test_perf_on_all git checkout-index -f --all
 test_perf_on_all git update-index --add --remove $SPARSE_CONE/a
 test_perf_on_all "git rm -f $SPARSE_CONE/a && git checkout HEAD -- $SPARSE_CONE/a"
 test_perf_on_all git grep --cached --sparse bogus -- "f2/f1/f1/*"
+test_perf_on_all git write-tree 
 
 test_done
t/t1092-sparse-checkout-compatibility.sh +28 -0
index 801919009e..3b8191b390 100755
@@ -2055,4 +2055,32 @@ test_expect_success 'grep sparse directory within submodules' '
 	test_cmp actual expect
 '
 
+test_expect_success 'write-tree on all' '
+	init_repos &&
+
+	write_script edit-contents <<-\EOF &&
+	echo text >>"$1"
+	EOF
+
+	run_on_all ../edit-contents deep/a &&
+	run_on_all git update-index deep/a &&
+	test_all_match git write-tree &&
+
+	run_on_all mkdir -p folder1 &&
+	run_on_all cp a folder1/a &&
+	run_on_all ../edit-contents folder1/a &&
+	run_on_all git update-index folder1/a &&
+	test_all_match git write-tree
+'
+
+test_expect_success 'sparse-index is not expanded: write-tree' '
+	init_repos &&
+
+	ensure_not_expanded write-tree &&
+
+	echo "test1" >>sparse-index/a &&
+	git -C sparse-index update-index a &&
+	ensure_not_expanded write-tree 
+'
+
 test_done
Signature · 1 line
2.39.0
#5 lore raw
Quoted 18 lines · Shuqi Liang

Update 'git write-tree' to allow using the sparse-index in memory without expanding to a full one.

The recursive algorithm for update_one() was already updated in 2de37c5 (cache-tree: integrate with sparse directory entries, 2021-03-03) to handle sparse directory entries in the index. Hence we can just set the requires-full-index to false for "write-tree".

The p2000 tests demonstrate a ~96% execution time reduction for 'git write-tree' using a sparse index:

Test before after
-----------------------------------------------------------------

2000.78: git write-tree (full-v3)              0.34    0.33 -2.9%
2000.79: git write-tree (full-v4)              0.32    0.30 -6.3%
2000.80: git write-tree (sparse-v3)            0.47    0.02 -95.8%
2000.81: git write-tree (sparse-v4)            0.45    0.02 -95.6%
Quoted 4 lines

---

* change the position of "settings.command_requires_full_index = 0"

Could you describe why you made this change? You don't need to re-roll, but in the future please make sure to describe the reasoning for changes like this in these version notes if the context can't be gathered from other discussions in the thread.

Quoted 63 lines

Range-diff against v1:
1: d8a9ccd0b3 ! 1: 8873c79759 write-tree: integrate with sparse index

    @@ Commit message
     
      ## builtin/write-tree.c ##
     @@ builtin/write-tree.c: int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
    - 	};
    - 
    - 	git_config(git_default_config, NULL);
    -+	
    -+	prepare_repo_settings(the_repository);
    -+	the_repository->settings.command_requires_full_index = 0;
    -+
      	argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
      			     write_tree_usage, 0);
      
    ++	prepare_repo_settings(the_repository);
    ++	the_repository->settings.command_requires_full_index = 0;
    ++	
    + 	ret = write_cache_as_tree(&oid, flags, tree_prefix);
    + 	switch (ret) {
    + 	case 0:
     
      ## t/perf/p2000-sparse-operations.sh ##
     @@ t/perf/p2000-sparse-operations.sh: test_perf_on_all git checkout-index -f --all
 builtin/write-tree.c                     |  3 +++
 t/perf/p2000-sparse-operations.sh        |  1 +
 t/t1092-sparse-checkout-compatibility.sh | 28 ++++++++++++++++++++++++
 3 files changed, 32 insertions(+)
builtin/write-tree.c +3 -0
index 45d61707e7..4492da0912 100644
@@ -38,6 +38,9 @@ int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
 	argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
 			     write_tree_usage, 0);
 
+	prepare_repo_settings(the_repository);
+	the_repository->settings.command_requires_full_index = 0;
+	
 	ret = write_cache_as_tree(&oid, flags, tree_prefix);
 	switch (ret) {
 	case 0:
t/perf/p2000-sparse-operations.sh +1 -0
index 3242cfe91a..9924adfc26 100755
@@ -125,5 +125,6 @@ test_perf_on_all git checkout-index -f --all
 test_perf_on_all git update-index --add --remove $SPARSE_CONE/a
 test_perf_on_all "git rm -f $SPARSE_CONE/a && git checkout HEAD -- $SPARSE_CONE/a"
 test_perf_on_all git grep --cached --sparse bogus -- "f2/f1/f1/*"
+test_perf_on_all git write-tree 
 
 test_done
t/t1092-sparse-checkout-compatibility.sh +0 -0
index 801919009e..3b8191b390 100755

t/t1092-sparse-checkout-compatibility.sh test_expect_success 'grep sparse directory within submodules' ' · line 2058

Quoted 4 lines
t/t1092-sparse-checkout-compatibility.sh +1 -0
@@ -2055,4 +2055,32 @@ test_expect_success 'grep sparse directory within submodules' '
 	test_cmp actual expect
 '
 
+test_expect_success 'write-tree on all' '

It's not clear what "on all" means in this context. If it's "write-tree with changes both inside and outside the cone", then please either make that explicit in the test name or simplify the name to just 'write-tree' (like 'clean').

t/t1092-sparse-checkout-compatibility.sh test_expect_success 'grep sparse directory within submodules' ' · line 2059

Quoted 1 line
t/t1092-sparse-checkout-compatibility.sh +1 -0
+	init_repos &&

It would be nice to have a baseline 'test_all_match git write-tree' before making any changes to the index (as you do in the 'sparse-index is not
expanded: write-tree' test).

t/t1092-sparse-checkout-compatibility.sh test_expect_success 'grep sparse directory within submodules' ' · line 2067

Quoted 8 lines
t/t1092-sparse-checkout-compatibility.sh +8 -0
+
+	write_script edit-contents <<-\EOF &&
+	echo text >>"$1"
+	EOF
+
+	run_on_all ../edit-contents deep/a &&
+	run_on_all git update-index deep/a &&
+	test_all_match git write-tree &&

First you make a change inside the sparse cone and 'write-tree'...

t/t1092-sparse-checkout-compatibility.sh test_expect_success 'grep sparse directory within submodules' ' · line 2073

Quoted 6 lines
t/t1092-sparse-checkout-compatibility.sh +6 -0
+
+	run_on_all mkdir -p folder1 &&
+	run_on_all cp a folder1/a &&
+	run_on_all ../edit-contents folder1/a &&
+	run_on_all git update-index folder1/a &&
+	test_all_match git write-tree

...then make a change outside the cone and 'write-tree' again. Makes sense.

However, there isn't any test of the working tree after 'write-tree' exits. For example, I'd be interested in seeing a comparison of the output of 'git status --porcelain=v2', as well as ensuring that SKIP_WORKTREE files weren't materialized on disk in 'sparse-checkout' and 'sparse-index' (e.g., 'folder2/a' shouldn't exist).

It also wouldn't hurt to 'test_all_match' on the 'git update-index' calls, but I don't feel too strongly either way.

t/t1092-sparse-checkout-compatibility.sh test_expect_success 'grep sparse directory within submodules' ' · line 2083

Quoted 10 lines
t/t1092-sparse-checkout-compatibility.sh +10 -0
+'
+
+test_expect_success 'sparse-index is not expanded: write-tree' '
+	init_repos &&
+
+	ensure_not_expanded write-tree &&
+
+	echo "test1" >>sparse-index/a &&
+	git -C sparse-index update-index a &&
+	ensure_not_expanded write-tree 

This also looks good.

Quoted 3 lines
t/t1092-sparse-checkout-compatibility.sh +2 -0
+'
+
 test_done
#6 lore raw
Quoted 22 lines · Victoria Dye
Quoted 21 lines · Shuqi Liang

Update 'git write-tree' to allow using the sparse-index in memory without expanding to a full one.

The recursive algorithm for update_one() was already updated in 2de37c5 (cache-tree: integrate with sparse directory entries, 2021-03-03) to handle sparse directory entries in the index. Hence we can just set the requires-full-index to false for "write-tree".

The p2000 tests demonstrate a ~96% execution time reduction for 'git write-tree' using a sparse index:

Test before after
-----------------------------------------------------------------

2000.78: git write-tree (full-v3)              0.34    0.33 -2.9%
2000.79: git write-tree (full-v4)              0.32    0.30 -6.3%
2000.80: git write-tree (sparse-v3)            0.47    0.02 -95.8%
2000.81: git write-tree (sparse-v4)            0.45    0.02 -95.6%

---

Quoted 6 lines
Quoted 1 line

* change the position of "settings.command_requires_full_index = 0"

Could you describe why you made this change? You don't need to re-roll, but in the future please make sure to describe the reasoning for changes like this in these version notes if the context can't be gathered from other discussions in the thread.

The reason, I think, is because previous iteration hit a BUG() when the command "git write-tree -h" is run outside a repository. That form of the help request is handled in the parse_options() machinery without any need to have a repository or a working tree.

But prepare_repo_settings() does need to be run inside a repository, so calling it without first checking if we are even in a repository is asking for trouble.

I guess an alternative fix could have been to see if we are indeed in a repository, by doing something like

	if (the_repository->gitdir) {
		prepare_repo_settings(the_repository);
		the_repository->settings.command_requires_full_index = 0;
	}

like implementations of some subcommands do. And being explicit that way, instead of relying on an implicit safety given by ordering of calls, would be more maintainable in the longer haul.

#7 lore raw

PATCH v3 1/1 write-tree: integrate with sparse index

In reply to Shuqi Liang

Update 'git write-tree' to allow using the sparse-index in memory without expanding to a full one.

The recursive algorithm for update_one() was already updated in 2de37c5 (cache-tree: integrate with sparse directory entries, 2021-03-03) to handle sparse directory entries in the index. Hence we can just set the requires-full-index to false for "write-tree".

The p2000 tests demonstrate a ~96% execution time reduction for 'git write-tree' using a sparse index:

Test before after
-----------------------------------------------------------------

2000.78: git write-tree (full-v3)              0.34    0.33 -2.9%
2000.79: git write-tree (full-v4)              0.32    0.30 -6.3%
2000.80: git write-tree (sparse-v3)            0.47    0.02 -95.8%
2000.81: git write-tree (sparse-v4)            0.45    0.02 -95.6%

---

* Modified the code to ensure prepare_repo_settings() is called only when inside a repository.

* Change 'write-tree on all' to just 'write-tree'.

* Have a baseline 'test_all_match git write-tree' before making any changes to the index.

* Add 'git status --porcelain=v2'.

* Ensuring that SKIP_WORKTREE files weren't materialized on disk by using "test_path_is_missing".

* Use 'test_all_match' on the 'git update-index'.

Range-diff against v2:
1: 8873c79759 ! 1: cfa43c6cc7 write-tree: integrate with sparse index

    @@ Commit message
     
      ## builtin/write-tree.c ##
     @@ builtin/write-tree.c: int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
    - 	argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
    - 			     write_tree_usage, 0);
    + 	};
      
    + 	git_config(git_default_config, NULL);
    ++	
    ++	if (the_repository->gitdir) {
     +	prepare_repo_settings(the_repository);
     +	the_repository->settings.command_requires_full_index = 0;
    -+	
    - 	ret = write_cache_as_tree(&oid, flags, tree_prefix);
    - 	switch (ret) {
    - 	case 0:
    ++	}
    ++
    + 	argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
    + 			     write_tree_usage, 0);
    + 
     
      ## t/perf/p2000-sparse-operations.sh ##
     @@ t/perf/p2000-sparse-operations.sh: test_perf_on_all git checkout-index -f --all
    @@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'grep sparse direc
      	test_cmp actual expect
      '
      
    -+test_expect_success 'write-tree on all' '
    ++test_expect_success 'write-tree' '
     +	init_repos &&
     +
    ++	test_all_match git write-tree &&
    ++
     +	write_script edit-contents <<-\EOF &&
     +	echo text >>"$1"
     +	EOF
     +
    ++	# make a change inside the sparse cone
     +	run_on_all ../edit-contents deep/a &&
    -+	run_on_all git update-index deep/a &&
    ++	test_all_match git update-index deep/a &&
     +	test_all_match git write-tree &&
    ++	test_all_match git status --porcelain=v2 &&
     +
    ++	# make a change outside the sparse cone
     +	run_on_all mkdir -p folder1 &&
     +	run_on_all cp a folder1/a &&
     +	run_on_all ../edit-contents folder1/a &&
    -+	run_on_all git update-index folder1/a &&
    -+	test_all_match git write-tree
    ++	test_all_match git update-index folder1/a &&
    ++	test_all_match git write-tree &&
    ++	test_all_match git status --porcelain=v2 &&
    ++	
    ++	# check that SKIP_WORKTREE files are not materialized
    ++	test_path_is_missing sparse-checkout/folder2/a &&
    ++	test_path_is_missing sparse-index/folder2/a
     +'
     +
     +test_expect_success 'sparse-index is not expanded: write-tree' '
 builtin/write-tree.c                     |  6 ++++
 t/perf/p2000-sparse-operations.sh        |  1 +
 t/t1092-sparse-checkout-compatibility.sh | 38 ++++++++++++++++++++++++
 3 files changed, 45 insertions(+)
builtin/write-tree.c +6 -0
index 45d61707e7..23d63844de 100644
@@ -35,6 +35,12 @@ int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
 	};
 
 	git_config(git_default_config, NULL);
+	
+	if (the_repository->gitdir) {
+	prepare_repo_settings(the_repository);
+	the_repository->settings.command_requires_full_index = 0;
+	}
+
 	argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
 			     write_tree_usage, 0);
 
t/perf/p2000-sparse-operations.sh +1 -0
index 3242cfe91a..9924adfc26 100755
@@ -125,5 +125,6 @@ test_perf_on_all git checkout-index -f --all
 test_perf_on_all git update-index --add --remove $SPARSE_CONE/a
 test_perf_on_all "git rm -f $SPARSE_CONE/a && git checkout HEAD -- $SPARSE_CONE/a"
 test_perf_on_all git grep --cached --sparse bogus -- "f2/f1/f1/*"
+test_perf_on_all git write-tree 
 
 test_done
t/t1092-sparse-checkout-compatibility.sh +38 -0
index 801919009e..d3eb31326b 100755
@@ -2055,4 +2055,42 @@ test_expect_success 'grep sparse directory within submodules' '
 	test_cmp actual expect
 '
 
+test_expect_success 'write-tree' '
+	init_repos &&
+
+	test_all_match git write-tree &&
+
+	write_script edit-contents <<-\EOF &&
+	echo text >>"$1"
+	EOF
+
+	# make a change inside the sparse cone
+	run_on_all ../edit-contents deep/a &&
+	test_all_match git update-index deep/a &&
+	test_all_match git write-tree &&
+	test_all_match git status --porcelain=v2 &&
+
+	# make a change outside the sparse cone
+	run_on_all mkdir -p folder1 &&
+	run_on_all cp a folder1/a &&
+	run_on_all ../edit-contents folder1/a &&
+	test_all_match git update-index folder1/a &&
+	test_all_match git write-tree &&
+	test_all_match git status --porcelain=v2 &&
+	
+	# check that SKIP_WORKTREE files are not materialized
+	test_path_is_missing sparse-checkout/folder2/a &&
+	test_path_is_missing sparse-index/folder2/a
+'
+
+test_expect_success 'sparse-index is not expanded: write-tree' '
+	init_repos &&
+
+	ensure_not_expanded write-tree &&
+
+	echo "test1" >>sparse-index/a &&
+	git -C sparse-index update-index a &&
+	ensure_not_expanded write-tree 
+'
+
 test_done
Signature · 1 line
2.39.0
#9 lore raw

Hi Junio,

Quoted 11 lines · Junio C Hamano
Quoted 2 lines · Shuqi Liang

Update 'git write-tree' to allow using the sparse-index in memory without expanding to a full one.

Sorry, but after this exchange

https://lore.kernel.org/git/[email protected]/

I am confused what we want to do with this version.

Apologies for not noticing the patch was already merged to master. I'll make the necessary changes and submit a new patch soon.

Thanks
Shuqi

#10 lore raw
Quoted 8 lines · Shuqi Liang
Quoted 5 lines

Sorry, but after this exchange

https://lore.kernel.org/git/[email protected]/

I am confused what we want to do with this version.

Apologies for not noticing the patch was already merged to master. I'll make the necessary changes and submit a new patch soon.

No need to apologize. I should have been able to guess what happend myself.

Thanks for offering to make your updates incremental. Will look forward to seeing them.

#11 lore raw

PATCH v4 1/1 write-tree: integrate with sparse index

In reply to Shuqi Liang

Update 'git write-tree' to allow using the sparse-index in memory without expanding to a full one.

The recursive algorithm for update_one() was already updated in 2de37c5 (cache-tree: integrate with sparse directory entries, 2021-03-03) to handle sparse directory entries in the index. Hence we can just set the requires-full-index to false for "write-tree".

The p2000 tests demonstrate a ~96% execution time reduction for 'git write-tree' using a sparse index:

Test before after
-----------------------------------------------------------------

2000.78: git write-tree (full-v3)              0.34    0.33 -2.9%
2000.79: git write-tree (full-v4)              0.32    0.30 -6.3%
2000.80: git write-tree (sparse-v3)            0.47    0.02 -95.8%
2000.81: git write-tree (sparse-v4)            0.45    0.02 -95.6%

---

* Modified the code to ensure prepare_repo_settings() is called only when inside a repository.

* Change 'write-tree on all' to just 'write-tree'.

* Have a baseline 'test_all_match git write-tree' before making any changes to the index.

* Add 'git status --porcelain=v2'.

* Ensuring that SKIP_WORKTREE files weren't materialized on disk by using "test_path_is_missing".

* Use 'test_all_match' on the 'git update-index'.

 builtin/write-tree.c                     |  9 ++++++---
 t/t1092-sparse-checkout-compatibility.sh | 20 +++++++++++++++-----
 2 files changed, 21 insertions(+), 8 deletions(-)
builtin/write-tree.c +6 -3
index 32e302a813..a9d5c20cde 100644
@@ -38,12 +38,15 @@ int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
 	};
 
 	git_config(git_default_config, NULL);
+	
+	if (the_repository->gitdir) {
+		prepare_repo_settings(the_repository);
+		the_repository->settings.command_requires_full_index = 0;
+	}
+
 	argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
 			     write_tree_usage, 0);
 
-	prepare_repo_settings(the_repository);
-	the_repository->settings.command_requires_full_index = 0;
-
 	ret = write_index_as_tree(&oid, &the_index, get_index_file(), flags,
 				  tree_prefix);
 	switch (ret) {
t/t1092-sparse-checkout-compatibility.sh +15 -5
index 9bbc0d646b..d3eb31326b 100755
@@ -2055,22 +2055,32 @@ test_expect_success 'grep sparse directory within submodules' '
 	test_cmp actual expect
 '
 
-test_expect_success 'write-tree on all' '
+test_expect_success 'write-tree' '
 	init_repos &&
 
+	test_all_match git write-tree &&
+
 	write_script edit-contents <<-\EOF &&
 	echo text >>"$1"
 	EOF
 
+	# make a change inside the sparse cone
 	run_on_all ../edit-contents deep/a &&
-	run_on_all git update-index deep/a &&
+	test_all_match git update-index deep/a &&
 	test_all_match git write-tree &&
+	test_all_match git status --porcelain=v2 &&
 
+	# make a change outside the sparse cone
 	run_on_all mkdir -p folder1 &&
 	run_on_all cp a folder1/a &&
 	run_on_all ../edit-contents folder1/a &&
-	run_on_all git update-index folder1/a &&
-	test_all_match git write-tree
+	test_all_match git update-index folder1/a &&
+	test_all_match git write-tree &&
+	test_all_match git status --porcelain=v2 &&
+	
+	# check that SKIP_WORKTREE files are not materialized
+	test_path_is_missing sparse-checkout/folder2/a &&
+	test_path_is_missing sparse-index/folder2/a
 '
 
 test_expect_success 'sparse-index is not expanded: write-tree' '
@@ -2080,7 +2090,7 @@ test_expect_success 'sparse-index is not expanded: write-tree' '
 
 	echo "test1" >>sparse-index/a &&
 	git -C sparse-index update-index a &&
-	ensure_not_expanded write-tree
+	ensure_not_expanded write-tree 
 '
 
 test_done
Signature · 1 line
2.39.0
#12 lore raw
Quoted 11 lines · Shuqi Liang

Update 'git write-tree' to allow using the sparse-index in memory without expanding to a full one.

The recursive algorithm for update_one() was already updated in 2de37c5 (cache-tree: integrate with sparse directory entries, 2021-03-03) to handle sparse directory entries in the index. Hence we can just set the requires-full-index to false for "write-tree".

The p2000 tests demonstrate a ~96% execution time reduction for 'git write-tree' using a sparse index:

Quoted 6 lines

Test before after
-----------------------------------------------------------------

2000.78: git write-tree (full-v3)              0.34    0.33 -2.9%
2000.79: git write-tree (full-v4)              0.32    0.30 -6.3%
2000.80: git write-tree (sparse-v3)            0.47    0.02 -95.8%
2000.81: git write-tree (sparse-v4)            0.45    0.02 -95.6%

Please update your commit message to explain only the incremental updates on top of 1a65b41b38a (write-tree: integrate with sparse index, 2023-04-03); that patch's message (what you have here) does not accurately describe what _this_ patch is doing.

Quoted 10 lines
builtin/write-tree.c +2 -0
index 32e302a813..a9d5c20cde 100644
@@ -38,12 +38,15 @@ int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
 	};
 
 	git_config(git_default_config, NULL);
+	
+	if (the_repository->gitdir) {

builtin/write-tree.c int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix) · line 46

Quoted 10 lines
builtin/write-tree.c +4 -3
+		prepare_repo_settings(the_repository);
+		the_repository->settings.command_requires_full_index = 0;
+	}
+
 	argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
 			     write_tree_usage, 0);
 
-	prepare_repo_settings(the_repository);
-	the_repository->settings.command_requires_full_index = 0;
-

What is the functional benefit of this change? AFAICT, we don't need 'command_requires_full_index' to be set before 'parse_options' in this case, so this won't have any effect on the behavior of 'write-tree'.

Quoted 28 lines
t/t1092-sparse-checkout-compatibility.sh +7 -2
index 9bbc0d646b..d3eb31326b 100755
@@ -2055,22 +2055,32 @@ test_expect_success 'grep sparse directory within submodules' '
 	test_cmp actual expect
 '
 
-test_expect_success 'write-tree on all' '
+test_expect_success 'write-tree' '
 	init_repos &&
 
+	test_all_match git write-tree &&
+
 	write_script edit-contents <<-\EOF &&
 	echo text >>"$1"
 	EOF
 
+	# make a change inside the sparse cone
 	run_on_all ../edit-contents deep/a &&
-	run_on_all git update-index deep/a &&
+	test_all_match git update-index deep/a &&
 	test_all_match git write-tree &&
+	test_all_match git status --porcelain=v2 &&
 
+	# make a change outside the sparse cone
 	run_on_all mkdir -p folder1 &&
 	run_on_all cp a folder1/a &&

t/t1092-sparse-checkout-compatibility.sh test_expect_success 'grep sparse directory within submodules' ' · line 2083

Quoted 10 lines
t/t1092-sparse-checkout-compatibility.sh +7 -2
 	run_on_all ../edit-contents folder1/a &&
-	run_on_all git update-index folder1/a &&
-	test_all_match git write-tree
+	test_all_match git update-index folder1/a &&
+	test_all_match git write-tree &&
+	test_all_match git status --porcelain=v2 &&
+	
+	# check that SKIP_WORKTREE files are not materialized
+	test_path_is_missing sparse-checkout/folder2/a &&
+	test_path_is_missing sparse-index/folder2/a

Test updates look good!

t/t1092-sparse-checkout-compatibility.sh test_expect_success 'sparse-index is not expanded: write-tree' ' · line 2093

Quoted 9 lines
t/t1092-sparse-checkout-compatibility.sh +1 -1
 '
 
 test_expect_success 'sparse-index is not expanded: write-tree' '
@@ -2080,7 +2090,7 @@ test_expect_success 'sparse-index is not expanded: write-tree' '
 
 	echo "test1" >>sparse-index/a &&
 	git -C sparse-index update-index a &&
-	ensure_not_expanded write-tree
+	ensure_not_expanded write-tree 

nit: trailing whitespace should be removed

Quoted 3 lines
t/t1092-sparse-checkout-compatibility.sh +0 -0
 '
 
 test_done
#13 lore raw
Quoted 19 lines · Victoria Dye
Quoted 11 lines · Shuqi Liang

Update 'git write-tree' to allow using the sparse-index in memory without expanding to a full one.

The recursive algorithm for update_one() was already updated in 2de37c5 (cache-tree: integrate with sparse directory entries, 2021-03-03) to handle sparse directory entries in the index. Hence we can just set the requires-full-index to false for "write-tree".

The p2000 tests demonstrate a ~96% execution time reduction for 'git write-tree' using a sparse index:

Quoted 6 lines

Test before after
-----------------------------------------------------------------

2000.78: git write-tree (full-v3)              0.34    0.33 -2.9%
2000.79: git write-tree (full-v4)              0.32    0.30 -6.3%
2000.80: git write-tree (sparse-v3)            0.47    0.02 -95.8%
2000.81: git write-tree (sparse-v4)            0.45    0.02 -95.6%
Quoted 4 lines

Please update your commit message to explain only the incremental updates on top of 1a65b41b38a (write-tree: integrate with sparse index, 2023-04-03); that patch's message (what you have here) does not accurately describe what _this_ patch is doing.

Good point.

In addition, as this is the first iteration of a follow-up topic, "v4" on the subject line is a bit misleading. Let's treat it as a new and separate topic that build on top of the previous achievement.

Thanks for working on this topic and mentoring a new contributor.

#14 lore raw

PATCH v5 1/1 write-tree: optimize sparse integration

In reply to Shuqi Liang

'prepare_repo_settings()' needs to be run inside a repository. Ensure that the code checks for the presence of a repository before calling this function. 'write-tree on all' had an unclear meaning of 'on all'. Change the test name to simply 'write-tree'. Add a baseline 'test_all_match git write-tree' before making any changes to the index, providing a reference point for the 'write-tree' prior to any modifications. Add a comparison of the output of
'git status --porcelain=v2' to test the working tree after 'write-tree' exits. Ensure SKIP_WORKTREE files weren't materialized on disk by using "test_path_is_missing".

---

* Update commit message.

* 'command_requires_full_index' to be set after 'parse_options'.

* Remove trailing whitespace.

Range-diff against v4:
1: 07f9bbd3c4 ! 1: df470c2d61 write-tree: integrate with sparse index
@@ Metadata
Author: Shuqi Liang <[email protected]>

## Commit message ##
- write-tree: integrate with sparse index
+ write-tree: optimize sparse integration

- Update 'git write-tree' to allow using the sparse-index in memory
- without expanding to a full one.
-
- The recursive algorithm for update_one() was already updated in 2de37c5
- (cache-tree: integrate with sparse directory entries, 2021-03-03) to
- handle sparse directory entries in the index. Hence we can just set the
- requires-full-index to false for "write-tree".
-
- The p2000 tests demonstrate a ~96% execution time reduction for 'git
- write-tree' using a sparse index:
-
- Test before after
- -----------------------------------------------------------------
- 2000.78: git write-tree (full-v3) 0.34 0.33 -2.9%
- 2000.79: git write-tree (full-v4) 0.32 0.30 -6.3%
- 2000.80: git write-tree (sparse-v3) 0.47 0.02 -95.8%
- 2000.81: git write-tree (sparse-v4) 0.45 0.02 -95.6%
+ 'prepare_repo_settings()' needs to be run inside a repository. Ensure
+ that the code checks for the presence of a repository before calling
+ this function. 'write-tree on all' had an unclear meaning of 'on all'.
+ Change the test name to simply 'write-tree'. Add a baseline
+ 'test_all_match git write-tree' before making any changes to the index,
+ providing a reference point for the 'write-tree' prior to any
+ modifications. Add a comparison of the output of
+ 'git status --porcelain=v2' to test the working tree after 'write-tree'
+ exits. Ensure SKIP_WORKTREE files weren't materialized on disk by using
+ "test_path_is_missing".

## builtin/write-tree.c ##
@@ builtin/write-tree.c: int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
- };
+ argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
+ write_tree_usage, 0);

- git_config(git_default_config, NULL);
-+
+- prepare_repo_settings(the_repository);
+- the_repository->settings.command_requires_full_index = 0;
+ if (the_repository->gitdir) {
+ prepare_repo_settings(the_repository);
+ the_repository->settings.command_requires_full_index = 0;
+ }
-+
- argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
- write_tree_usage, 0);

-- prepare_repo_settings(the_repository);
-- the_repository->settings.command_requires_full_index = 0;
--
ret = write_index_as_tree(&oid, &the_index, get_index_file(), flags,
tree_prefix);
- switch (ret) {

## t/t1092-sparse-checkout-compatibility.sh ##
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'grep sparse directory within submodules' '
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'grep sparse direc
'

test_expect_success 'sparse-index is not expanded: write-tree' '
-@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'sparse-index is not expanded: write-tree' ' -
- echo "test1" >>sparse-index/a &&
- git -C sparse-index update-index a &&
-- ensure_not_expanded write-tree
-+ ensure_not_expanded write-tree
- '
-
- test_done

 builtin/write-tree.c                     |  6 ++++--
 t/t1092-sparse-checkout-compatibility.sh | 18 ++++++++++++++----
 2 files changed, 18 insertions(+), 6 deletions(-)
builtin/write-tree.c +4 -2
index 32e302a813..52caa096a8 100644
@@ -41,8 +41,10 @@ int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
 	argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
 			     write_tree_usage, 0);
 
-	prepare_repo_settings(the_repository);
-	the_repository->settings.command_requires_full_index = 0;
+	if (the_repository->gitdir) {
+		prepare_repo_settings(the_repository);
+		the_repository->settings.command_requires_full_index = 0;
+	}
 
 	ret = write_index_as_tree(&oid, &the_index, get_index_file(), flags,
 				  tree_prefix);
t/t1092-sparse-checkout-compatibility.sh +14 -4
index 0c784813f1..2a467e4b31 100755
@@ -2080,22 +2080,32 @@ test_expect_success 'grep sparse directory within submodules' '
 	test_cmp actual expect
 '
 
-test_expect_success 'write-tree on all' '
+test_expect_success 'write-tree' '
 	init_repos &&
 
+	test_all_match git write-tree &&
+
 	write_script edit-contents <<-\EOF &&
 	echo text >>"$1"
 	EOF
 
+	# make a change inside the sparse cone
 	run_on_all ../edit-contents deep/a &&
-	run_on_all git update-index deep/a &&
+	test_all_match git update-index deep/a &&
 	test_all_match git write-tree &&
+	test_all_match git status --porcelain=v2 &&
 
+	# make a change outside the sparse cone
 	run_on_all mkdir -p folder1 &&
 	run_on_all cp a folder1/a &&
 	run_on_all ../edit-contents folder1/a &&
-	run_on_all git update-index folder1/a &&
-	test_all_match git write-tree
+	test_all_match git update-index folder1/a &&
+	test_all_match git write-tree &&
+	test_all_match git status --porcelain=v2 &&
+	
+	# check that SKIP_WORKTREE files are not materialized
+	test_path_is_missing sparse-checkout/folder2/a &&
+	test_path_is_missing sparse-index/folder2/a
 '
 
 test_expect_success 'sparse-index is not expanded: write-tree' '
Signature · 1 line
2.39.0
#15 lore raw

Re: [PATCH v5] write-tree: optimize sparse integration

Quoted 3 lines · Shuqi Liang

'prepare_repo_settings()' needs to be run inside a repository. Ensure that the code checks for the presence of a repository before calling this function.

Can you explain why this change is needed?

That is, if the caller made sure if this codepath is entered only when inside a repository, such a "we need to refrain from doing this" becomes unnecessary. Describe under what condition the control passes this section with !the_repository->gitdir, e.g. "When the command is run in such and such way outside a repository, the control reaches this position but prepare_repo_settings() cannot be blindly called".

I suspect that it is a bug if the control reaches this point without having a repository, as the call to write_index_as_tree() would be already failing if we were not in a repository, but there is no such a bug, and you did not introduce one with your previous changes to this codepath that you need to fix here. You can observe a few things:

- "write-tree" in the git.c::commands[] table has RUN_SETUP.

- git.c::run_builtin() is repsonsible for calling cmd_write_tree(); what happens before it calls the function? For a command with RUN_SETUP set, unless the command line argument is "-h" (that is, "git write-tree -h" is run), setup_git_directory() is called.

- setup_git_directory() dies unless run in a repository.

- git.c::run_builtin() calls setup_git_directory_gently() when the command line argument is "-h" and it does not die even run outside a repository. However, before the code you touched, there is a call to parse_options().

- parse_options() called for the command line argument "-h" shows a short help and then exits.

So...?

Also when starting to talk about totally different things (like, you were discussing the change to write_tree.c to avoid segfaulting when run outside a repository, but now you are going to talk about the title of one test piece), please make sure it is clear for readers. A blank line here may be appropriate.

Quoted 8 lines

'write-tree on all' had an unclear meaning of 'on all'. Change the test name to simply 'write-tree'. Add a baseline 'test_all_match git write-tree' before making any changes to the index, providing a reference point for the 'write-tree' prior to any modifications. Add a comparison of the output of
'git status --porcelain=v2' to test the working tree after 'write-tree' exits. Ensure SKIP_WORKTREE files weren't materialized on disk by using "test_path_is_missing".

All of the above may be easier to read in a bulletted list form, e.g.

* 'on all' in the title of the test 'write-tree on all' was unclear; remove it.

* test the baseline test_all_match git write-tree" before doing anything else.

...

Quoted 4 lines

---

* Update commit message.

OK.

Quoted 1 line

* 'command_requires_full_index' to be set after 'parse_options'.

This does not match what we see in this patch.

Quoted 1 line

* Remove trailing whitespace.

OK. But there is a new line with a trailing whitespace before the line that says # check that SKIP_WORKTREE files are not materialized" in the test.

Thanks.

#16 lore raw

PATCH v6 1/1 write-tree: optimize sparse integration

In reply to Shuqi Liang

* Remove 'on all' from the test title 'write-tree on all', making it 'write-tree'.

* Add a baseline 'test_all_match git write-tree' before making any changes to the index, providing a reference point for the 'write-tree' prior to any modifications.

* Add a comparison of the output of 'git status --porcelain=v2' to test the working tree after 'write-tree' exits.

* Ensure SKIP_WORKTREE files weren't materialized on disk by using "test_path_is_missing".

---

change sine V5:

* We not need to check for the presence of a repository before calling 'prepare_repo_settings()', as the control flow should not reach this point without a repository. This is because 'setup_git_directory()' is called for commands with RUN_SETUP set, except when the command line argument is "-h", in which case 'parse_options()' takes over and exits the program.

* Change the commit message to make it easier to read.

* Remove whitespace before the line that says # check that SKIP_WORKTREE files are not materialized".

Range-diff against v5:
1: df470c2d61 ! 1: 0510b08c96 write-tree: optimize sparse integration
@@ Metadata
## Commit message ##
write-tree: optimize sparse integration

- 'prepare_repo_settings()' needs to be run inside a repository. Ensure
- that the code checks for the presence of a repository before calling
- this function. 'write-tree on all' had an unclear meaning of 'on all'.
- Change the test name to simply 'write-tree'. Add a baseline
- 'test_all_match git write-tree' before making any changes to the index,
- providing a reference point for the 'write-tree' prior to any
- modifications. Add a comparison of the output of
- 'git status --porcelain=v2' to test the working tree after 'write-tree'
- exits. Ensure SKIP_WORKTREE files weren't materialized on disk by using
+ * Remove 'on all' from the test title 'write-tree on all', making it
+ 'write-tree'.
+
+ * Add a baseline 'test_all_match git write-tree' before making any
+ changes to the index, providing a reference point for the 'write-tree'
+ prior to any modifications.
+
+ * Add a comparison of the output of 'git status --porcelain=v2' to test
+ the working tree after 'write-tree' exits.
+
+ * Ensure SKIP_WORKTREE files weren't materialized on disk by using
"test_path_is_missing".

- ## builtin/write-tree.c ##
-@@ builtin/write-tree.c: int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
- argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
- write_tree_usage, 0);
-
-- prepare_repo_settings(the_repository);
-- the_repository->settings.command_requires_full_index = 0;
-+ if (the_repository->gitdir) {
-+ prepare_repo_settings(the_repository);
-+ the_repository->settings.command_requires_full_index = 0;
-+ }
-
- ret = write_index_as_tree(&oid, &the_index, get_index_file(), flags,
- tree_prefix);
-
## t/t1092-sparse-checkout-compatibility.sh ##
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'grep sparse directory within submodules' '
test_cmp actual expect
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'grep sparse direc
+ test_all_match git update-index folder1/a &&
+ test_all_match git write-tree &&
+ test_all_match git status --porcelain=v2 &&
-+
++
+ # check that SKIP_WORKTREE files are not materialized
+ test_path_is_missing sparse-checkout/folder2/a &&
+ test_path_is_missing sparse-index/folder2/a

Signature · 2 lines
 t/t1092-sparse-checkout-compatibility.sh | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
t/t1092-sparse-checkout-compatibility.sh +14 -4
index 0c784813f1..3aa6356a85 100755
@@ -2080,22 +2080,32 @@ test_expect_success 'grep sparse directory within submodules' '
 	test_cmp actual expect
 '
 
-test_expect_success 'write-tree on all' '
+test_expect_success 'write-tree' '
 	init_repos &&
 
+	test_all_match git write-tree &&
+
 	write_script edit-contents <<-\EOF &&
 	echo text >>"$1"
 	EOF
 
+	# make a change inside the sparse cone
 	run_on_all ../edit-contents deep/a &&
-	run_on_all git update-index deep/a &&
+	test_all_match git update-index deep/a &&
 	test_all_match git write-tree &&
+	test_all_match git status --porcelain=v2 &&
 
+	# make a change outside the sparse cone
 	run_on_all mkdir -p folder1 &&
 	run_on_all cp a folder1/a &&
 	run_on_all ../edit-contents folder1/a &&
-	run_on_all git update-index folder1/a &&
-	test_all_match git write-tree
+	test_all_match git update-index folder1/a &&
+	test_all_match git write-tree &&
+	test_all_match git status --porcelain=v2 &&
+
+	# check that SKIP_WORKTREE files are not materialized
+	test_path_is_missing sparse-checkout/folder2/a &&
+	test_path_is_missing sparse-index/folder2/a
 '
 
 test_expect_success 'sparse-index is not expanded: write-tree' '
Signature · 1 line
2.39.0
#17 lore raw

PATCH v6 1/1 write-tree: optimize sparse integration

* 'on all' in the title of the test 'write-tree on all' was unclear; remove it.

* Add a baseline 'test_all_match git write-tree' before making any changes to the index, providing a reference point for the 'write-tree' prior to any modifications.

* Add a comparison of the output of 'git status --porcelain=v2' to test the working tree after 'write-tree' exits.

* Ensure SKIP_WORKTREE files weren't materialized on disk by using "test_path_is_missing".

---

My apologies, please ignore the previous v6 iteration.

change sine V5:

* We not need to check for the presence of a repository before calling 'prepare_repo_settings()', as the control flow should not reach this point without a repository. This is because 'setup_git_directory()' is called for commands with RUN_SETUP set, except when the command line argument is "-h", in which case 'parse_options()' takes over and exits the program.

* Change the commit message to make it easier to read.

* Remove whitespace before the line that says # check that SKIP_WORKTREE files are not materialized".

Range-diff against v5:
1: df470c2d61 ! 1: e6c21ec6b8 write-tree: optimize sparse integration
@@ Metadata
## Commit message ##
write-tree: optimize sparse integration

- 'prepare_repo_settings()' needs to be run inside a repository. Ensure
- that the code checks for the presence of a repository before calling
- this function. 'write-tree on all' had an unclear meaning of 'on all'.
- Change the test name to simply 'write-tree'. Add a baseline
- 'test_all_match git write-tree' before making any changes to the index,
- providing a reference point for the 'write-tree' prior to any
- modifications. Add a comparison of the output of
- 'git status --porcelain=v2' to test the working tree after 'write-tree'
- exits. Ensure SKIP_WORKTREE files weren't materialized on disk by using
+ * 'on all' in the title of the test 'write-tree on all' was unclear;
+ remove it.
+
+ * Add a baseline 'test_all_match git write-tree' before making any
+ changes to the index, providing a reference point for the 'write-tree'
+ prior to any modifications.
+
+ * Add a comparison of the output of 'git status --porcelain=v2' to test
+ the working tree after 'write-tree' exits.
+
+ * Ensure SKIP_WORKTREE files weren't materialized on disk by using
"test_path_is_missing".

- ## builtin/write-tree.c ##
-@@ builtin/write-tree.c: int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
- argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
- write_tree_usage, 0);
-
-- prepare_repo_settings(the_repository);
-- the_repository->settings.command_requires_full_index = 0;
-+ if (the_repository->gitdir) {
-+ prepare_repo_settings(the_repository);
-+ the_repository->settings.command_requires_full_index = 0;
-+ }
-
- ret = write_index_as_tree(&oid, &the_index, get_index_file(), flags,
- tree_prefix);
-
## t/t1092-sparse-checkout-compatibility.sh ##
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'grep sparse directory within submodules' '
test_cmp actual expect
@@ t/t1092-sparse-checkout-compatibility.sh: test_expect_success 'grep sparse direc
+ test_all_match git update-index folder1/a &&
+ test_all_match git write-tree &&
+ test_all_match git status --porcelain=v2 &&
-+
++
+ # check that SKIP_WORKTREE files are not materialized
+ test_path_is_missing sparse-checkout/folder2/a &&
+ test_path_is_missing sparse-index/folder2/a

Signature · 2 lines
 t/t1092-sparse-checkout-compatibility.sh | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
t/t1092-sparse-checkout-compatibility.sh +14 -4
index 0c784813f1..3aa6356a85 100755
@@ -2080,22 +2080,32 @@ test_expect_success 'grep sparse directory within submodules' '
 	test_cmp actual expect
 '
 
-test_expect_success 'write-tree on all' '
+test_expect_success 'write-tree' '
 	init_repos &&
 
+	test_all_match git write-tree &&
+
 	write_script edit-contents <<-\EOF &&
 	echo text >>"$1"
 	EOF
 
+	# make a change inside the sparse cone
 	run_on_all ../edit-contents deep/a &&
-	run_on_all git update-index deep/a &&
+	test_all_match git update-index deep/a &&
 	test_all_match git write-tree &&
+	test_all_match git status --porcelain=v2 &&
 
+	# make a change outside the sparse cone
 	run_on_all mkdir -p folder1 &&
 	run_on_all cp a folder1/a &&
 	run_on_all ../edit-contents folder1/a &&
-	run_on_all git update-index folder1/a &&
-	test_all_match git write-tree
+	test_all_match git update-index folder1/a &&
+	test_all_match git write-tree &&
+	test_all_match git status --porcelain=v2 &&
+
+	# check that SKIP_WORKTREE files are not materialized
+	test_path_is_missing sparse-checkout/folder2/a &&
+	test_path_is_missing sparse-index/folder2/a
 '
 
 test_expect_success 'sparse-index is not expanded: write-tree' '
Signature · 1 line
2.39.0
#18 lore raw

Re: [PATCH v6] write-tree: optimize sparse integration

Quoted 7 lines · Shuqi Liang

* 'on all' in the title of the test 'write-tree on all' was unclear; remove it.

* Add a baseline 'test_all_match git write-tree' before making any changes to the index, providing a reference point for the 'write-tree' prior to any modifications.

Quoted 9 lines

* Add a comparison of the output of 'git status --porcelain=v2' to test the working tree after 'write-tree' exits.

* Ensure SKIP_WORKTREE files weren't materialized on disk by using "test_path_is_missing".

---

As we have lost the change to the code, the title has become stale. How about I retitle it like so after queuing the patch?

Subject: t1092: update write-tree test

The changes to the test seem to match what Victoria already gave a thums-up in her review of v4; I see nothing surprising or unexpected there.

Thanks. Will queue.

#19 lore raw

Re: [PATCH v6] write-tree: optimize sparse integration

Hi Junio,

Quoted 16 lines · Junio C Hamano
Quoted 13 lines · Shuqi Liang

* 'on all' in the title of the test 'write-tree on all' was unclear; remove it.

* Add a baseline 'test_all_match git write-tree' before making any changes to the index, providing a reference point for the 'write-tree' prior to any modifications.

* Add a comparison of the output of 'git status --porcelain=v2' to test the working tree after 'write-tree' exits.

* Ensure SKIP_WORKTREE files weren't materialized on disk by using "test_path_is_missing".

Quoted 8 lines
Quoted 3 lines

---

As we have lost the change to the code, the title has become stale. How about I retitle it like so after queuing the patch?

Subject: t1092: update write-tree test

I think it's a good idea to retitle the patch, as it better reflects the current changes in the test.

Quoted 5 lines

The changes to the test seem to match what Victoria already gave a thums-up in her review of v4; I see nothing surprising or unexpected there.

Thanks. Will queue.

I really appreciate your and Victoria's continuous support and guidance throughout
the review process :)

Thanks!
Shuqi