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 <dstolee@microsoft.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Mar 27, 2020 at 00:48 UTC
30e89c12f0afc5c4382b531973a5e82b60d402bd
1 file changed
+16
-8
unpack-trees.c
+16
-8
@@ -1492,6 +1492,20 @@ static void mark_new_skip_worktree(struct pattern_list *pl,
1492
clear_ce_flags(istate, select_flag, skip_wt_flag, pl, show_progress);
1493
}
1494
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
+
1509
static int verify_absent(const struct cache_entry *,
1510
enum unpack_trees_error_types,
1511
struct unpack_trees_options *);
@@ -1512,18 +1526,12 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1526
die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
1527
1528
trace_performance_enter();
1515
- memset(&pl, 0, sizeof(pl));
1529
if (!core_apply_sparse_checkout || !o->update)
1530
o->skip_sparse_checkout = 1;
1531
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));
1533
free_pattern_list = 1;
1534
+ populate_from_existing_patterns(o, &pl);
1535
}
1536
1537
memset(&o->result, 0, sizeof(o->result));