Skip to content

Commit 23c25e8

Browse files
committed
read-tree: integrate with sparse index
Add repository setting setup for enabling sparse index usage with `read-tree`. In order to maintain behavior (and allow for focused adjustment of implementation in later commits), index is expanded when `--no-sparse-checkout` or `--prefix` is specified. Substantial performance improvement for sparse index indicated by `p2000` results: Test before after ----------------------------------------------------------------------------- git read-tree -mu HEAD (full-v3) 1.21(0.94+0.30) 1.37(1.06+0.33) +13.2% git read-tree -mu HEAD (full-v4) 1.18(0.90+0.28) 1.35(1.06+0.31) +14.4% git read-tree -mu HEAD (sparse-v3) 1.61(1.23+0.40) 0.14(0.07+0.05) -91.3% git read-tree -mu HEAD (sparse-v4) 2.16(1.52+0.48) 0.14(0.07+0.05) -93.5% Signed-off-by: Victoria Dye <[email protected]>
1 parent 57e8935 commit 23c25e8

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

builtin/read-tree.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,15 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
168168
argc = parse_options(argc, argv, cmd_prefix, read_tree_options,
169169
read_tree_usage, 0);
170170

171-
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
172-
173171
prefix_set = opts.prefix ? 1 : 0;
174172
if (1 < opts.merge + opts.reset + prefix_set)
175173
die("Which one? -m, --reset, or --prefix?");
176174

175+
prepare_repo_settings(the_repository);
176+
the_repository->settings.command_requires_full_index = 0;
177+
178+
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
179+
177180
/*
178181
* NEEDSWORK
179182
*
@@ -214,6 +217,10 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
214217
if (opts.merge && !opts.index_only)
215218
setup_work_tree();
216219

220+
/* TODO: audit sparse index behavior in unpack_trees */
221+
if (opts.skip_sparse_checkout || opts.prefix)
222+
ensure_full_index(&the_index);
223+
217224
if (opts.merge) {
218225
switch (stage - 1) {
219226
case 0:
@@ -223,11 +230,21 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
223230
opts.fn = opts.prefix ? bind_merge : oneway_merge;
224231
break;
225232
case 2:
233+
/*
234+
* TODO: update twoway_merge to handle edit/edit conflicts in
235+
* sparse directories.
236+
*/
237+
ensure_full_index(&the_index);
226238
opts.fn = twoway_merge;
227239
opts.initial_checkout = is_cache_unborn();
228240
break;
229241
case 3:
230242
default:
243+
/*
244+
* TODO: update threeway_merge to handle edit/edit conflicts in
245+
* sparse directories.
246+
*/
247+
ensure_full_index(&the_index);
231248
opts.fn = threeway_merge;
232249
break;
233250
}

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,17 @@ test_expect_success 'sparse index is not expanded: update-index' '
12501250
ensure_not_expanded update-index --add --remove --again
12511251
'
12521252

1253+
test_expect_success 'sparse index is not expanded: read-tree' '
1254+
init_repos &&
1255+
1256+
ensure_not_expanded checkout -b test-branch update-folder1 &&
1257+
for MERGE_TREES in "update-folder2"
1258+
do
1259+
ensure_not_expanded read-tree -mu $MERGE_TREES &&
1260+
ensure_not_expanded reset --hard HEAD || return 1
1261+
done
1262+
'
1263+
12531264
# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
12541265
# in this scenario, but it shouldn't.
12551266
test_expect_success 'reset mixed and checkout orphan' '

0 commit comments

Comments
 (0)