Skip to content

Commit 5d4f4a5

Browse files
newrengitster
authored andcommitted
unpack-trees: clean up some flow control
The update_sparsity() function was introduced in commit 7af7a25 ("unpack-trees: add a new update_sparsity() function", 2020-03-27). Prior to that, unpack_trees() was used, but that had a few bugs because the needs of the caller were different, and different enough that unpack_trees() could not easily be modified to handle both usecases. The implementation detail that update_sparsity() was written by copying unpack_trees() and then streamlining it, and then modifying it in the needed ways still shows through in that there are leftover vestiges in both functions that are no longer needed. Clean them up. In particular: * update_sparsity() allows a pattern list to be passed in, but unpack_trees() never should use a different pattern list. Add a check and a BUG() if this gets violated. * update_sparsity() has a check early on that will BUG() if o->skip_sparse_checkout is set; as such, there's no need to check for that condition again later in the code. We can simply remove the check and its corresponding goto label. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d144a9d commit 5d4f4a5

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

unpack-trees.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
18731873
die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
18741874
if (o->dir)
18751875
BUG("o->dir is for internal use only");
1876+
if (o->pl)
1877+
BUG("o->pl is for internal use only");
18761878

18771879
trace_performance_enter();
18781880
trace2_region_enter("unpack_trees", "unpack_trees", the_repository);
@@ -1899,7 +1901,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
18991901

19001902
if (!core_apply_sparse_checkout || !o->update)
19011903
o->skip_sparse_checkout = 1;
1902-
if (!o->skip_sparse_checkout && !o->pl) {
1904+
if (!o->skip_sparse_checkout) {
19031905
memset(&pl, 0, sizeof(pl));
19041906
free_pattern_list = 1;
19051907
populate_from_existing_patterns(o, &pl);
@@ -2113,8 +2115,6 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o)
21132115
memset(&pl, 0, sizeof(pl));
21142116
free_pattern_list = 1;
21152117
populate_from_existing_patterns(o, &pl);
2116-
if (o->skip_sparse_checkout)
2117-
goto skip_sparse_checkout;
21182118
}
21192119

21202120
/* Expand sparse directories as needed */
@@ -2142,7 +2142,6 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o)
21422142
ret = UPDATE_SPARSITY_WARNINGS;
21432143
}
21442144

2145-
skip_sparse_checkout:
21462145
if (check_updates(o, o->src_index))
21472146
ret = UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES;
21482147

0 commit comments

Comments
 (0)