Skip to content

Commit 836e25c

Browse files
derrickstoleegitster
authored andcommitted
sparse-checkout: hold pattern list in index
As we modify the sparse-checkout definition, we perform index operations on a pattern_list that only exists in-memory. This allows easy backing out in case the index update fails. However, if the index write itself cares about the sparse-checkout pattern set, we need access to that in-memory copy. Place a pointer to a 'struct pattern_list' in the index so we can access this on-demand. This will be used in the next change which uses the sparse-checkout definition to filter out directories that are outside the sparse cone. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6863df3 commit 836e25c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

builtin/sparse-checkout.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ static int update_working_directory(struct pattern_list *pl)
110110
if (is_index_unborn(r->index))
111111
return UPDATE_SPARSITY_SUCCESS;
112112

113+
r->index->sparse_checkout_patterns = pl;
114+
113115
memset(&o, 0, sizeof(o));
114116
o.verbose_update = isatty(2);
115117
o.update = 1;
@@ -138,6 +140,7 @@ static int update_working_directory(struct pattern_list *pl)
138140
else
139141
rollback_lock_file(&lock_file);
140142

143+
r->index->sparse_checkout_patterns = NULL;
141144
return result;
142145
}
143146

@@ -517,19 +520,18 @@ static int modify_pattern_list(int argc, const char **argv, enum modify_type m)
517520
{
518521
int result;
519522
int changed_config = 0;
520-
struct pattern_list pl;
521-
memset(&pl, 0, sizeof(pl));
523+
struct pattern_list *pl = xcalloc(1, sizeof(*pl));
522524

523525
switch (m) {
524526
case ADD:
525527
if (core_sparse_checkout_cone)
526-
add_patterns_cone_mode(argc, argv, &pl);
528+
add_patterns_cone_mode(argc, argv, pl);
527529
else
528-
add_patterns_literal(argc, argv, &pl);
530+
add_patterns_literal(argc, argv, pl);
529531
break;
530532

531533
case REPLACE:
532-
add_patterns_from_input(&pl, argc, argv);
534+
add_patterns_from_input(pl, argc, argv);
533535
break;
534536
}
535537

@@ -539,12 +541,13 @@ static int modify_pattern_list(int argc, const char **argv, enum modify_type m)
539541
changed_config = 1;
540542
}
541543

542-
result = write_patterns_and_update(&pl);
544+
result = write_patterns_and_update(pl);
543545

544546
if (result && changed_config)
545547
set_config(MODE_NO_PATTERNS);
546548

547-
clear_pattern_list(&pl);
549+
clear_pattern_list(pl);
550+
free(pl);
548551
return result;
549552
}
550553

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ static inline unsigned int canon_mode(unsigned int mode)
307307
struct split_index;
308308
struct untracked_cache;
309309
struct progress;
310+
struct pattern_list;
310311

311312
struct index_state {
312313
struct cache_entry **cache;
@@ -338,6 +339,7 @@ struct index_state {
338339
struct mem_pool *ce_mem_pool;
339340
struct progress *progress;
340341
struct repository *repo;
342+
struct pattern_list *sparse_checkout_patterns;
341343
};
342344

343345
/* Name hashing */

0 commit comments

Comments
 (0)