Skip to content

Commit dd23022

Browse files
derrickstoleegitster
authored andcommitted
sparse-checkout: load sparse-checkout patterns
A future feature will want to load the sparse-checkout patterns into a pattern_list, but the current mechanism to do so is a bit complicated. This is made difficult due to needing to find the sparse-checkout file in different ways throughout the codebase. The logic implemented in the new get_sparse_checkout_patterns() was duplicated in populate_from_existing_patterns() in unpack-trees.c. Use the new method instead, keeping the logic around handling the struct unpack_trees_options. The callers to get_sparse_checkout_filename() in builtin/sparse-checkout.c manipulate the sparse-checkout file directly, so it is not appropriate to replace logic in that file with get_sparse_checkout_patterns(). Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6a9372f commit dd23022

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

builtin/sparse-checkout.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ static char const * const builtin_sparse_checkout_usage[] = {
2222
NULL
2323
};
2424

25-
static char *get_sparse_checkout_filename(void)
26-
{
27-
return git_pathdup("info/sparse-checkout");
28-
}
29-
3025
static void write_patterns_to_file(FILE *fp, struct pattern_list *pl)
3126
{
3227
int i;

dir.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,6 +2998,23 @@ void setup_standard_excludes(struct dir_struct *dir)
29982998
}
29992999
}
30003000

3001+
char *get_sparse_checkout_filename(void)
3002+
{
3003+
return git_pathdup("info/sparse-checkout");
3004+
}
3005+
3006+
int get_sparse_checkout_patterns(struct pattern_list *pl)
3007+
{
3008+
int res;
3009+
char *sparse_filename = get_sparse_checkout_filename();
3010+
3011+
pl->use_cone_patterns = core_sparse_checkout_cone;
3012+
res = add_patterns_from_file_to_list(sparse_filename, "", 0, pl, NULL);
3013+
3014+
free(sparse_filename);
3015+
return res;
3016+
}
3017+
30013018
int remove_path(const char *name)
30023019
{
30033020
char *slash;

dir.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ int is_empty_dir(const char *dir);
448448

449449
void setup_standard_excludes(struct dir_struct *dir);
450450

451+
char *get_sparse_checkout_filename(void);
452+
int get_sparse_checkout_patterns(struct pattern_list *pl);
451453

452454
/* Constants for remove_dir_recursively: */
453455

unpack-trees.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,14 +1549,10 @@ static void mark_new_skip_worktree(struct pattern_list *pl,
15491549
static void populate_from_existing_patterns(struct unpack_trees_options *o,
15501550
struct pattern_list *pl)
15511551
{
1552-
char *sparse = git_pathdup("info/sparse-checkout");
1553-
1554-
pl->use_cone_patterns = core_sparse_checkout_cone;
1555-
if (add_patterns_from_file_to_list(sparse, "", 0, pl, NULL) < 0)
1552+
if (get_sparse_checkout_patterns(pl) < 0)
15561553
o->skip_sparse_checkout = 1;
15571554
else
15581555
o->pl = pl;
1559-
free(sparse);
15601556
}
15611557

15621558

0 commit comments

Comments
 (0)