Skip to content

Commit 30e89c1

Browse files
newrengitster
authored andcommitted
unpack-trees: pull sparse-checkout pattern reading into a new function
Create a populate_from_existing_patterns() function for reading the path_patterns from $GIT_DIR/info/sparse-checkout so that we can re-use it elsewhere. Reviewed-by: Derrick Stolee <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3cc7c50 commit 30e89c1

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

unpack-trees.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,20 @@ static void mark_new_skip_worktree(struct pattern_list *pl,
14921492
clear_ce_flags(istate, select_flag, skip_wt_flag, pl, show_progress);
14931493
}
14941494

1495+
static void populate_from_existing_patterns(struct unpack_trees_options *o,
1496+
struct pattern_list *pl)
1497+
{
1498+
char *sparse = git_pathdup("info/sparse-checkout");
1499+
1500+
pl->use_cone_patterns = core_sparse_checkout_cone;
1501+
if (add_patterns_from_file_to_list(sparse, "", 0, pl, NULL) < 0)
1502+
o->skip_sparse_checkout = 1;
1503+
else
1504+
o->pl = pl;
1505+
free(sparse);
1506+
}
1507+
1508+
14951509
static int verify_absent(const struct cache_entry *,
14961510
enum unpack_trees_error_types,
14971511
struct unpack_trees_options *);
@@ -1512,18 +1526,12 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
15121526
die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
15131527

15141528
trace_performance_enter();
1515-
memset(&pl, 0, sizeof(pl));
15161529
if (!core_apply_sparse_checkout || !o->update)
15171530
o->skip_sparse_checkout = 1;
15181531
if (!o->skip_sparse_checkout && !o->pl) {
1519-
char *sparse = git_pathdup("info/sparse-checkout");
1520-
pl.use_cone_patterns = core_sparse_checkout_cone;
1521-
if (add_patterns_from_file_to_list(sparse, "", 0, &pl, NULL) < 0)
1522-
o->skip_sparse_checkout = 1;
1523-
else
1524-
o->pl = &pl;
1525-
free(sparse);
1532+
memset(&pl, 0, sizeof(pl));
15261533
free_pattern_list = 1;
1534+
populate_from_existing_patterns(o, &pl);
15271535
}
15281536

15291537
memset(&o->result, 0, sizeof(o->result));

0 commit comments

Comments
 (0)