Skip to content

Commit 1147c56

Browse files
newrengitster
authored andcommitted
sparse-checkout: avoid using internal API of unpack-trees
struct unpack_trees_options has the following field and comment: struct pattern_list *pl; /* for internal use */ Despite the internal-use comment, commit e091228 ("sparse-checkout: update working directory in-process", 2019-11-21) starting setting this field from an external caller. At the time, the only way around that would have been to modify unpack_trees() to take an extra pattern_list argument, and there's a lot of callers of that function. However, when we split update_sparsity() off as a separate function, with sparse-checkout being the sole caller, the need to update other callers went away. Fix this API problem by adding a pattern_list argument to update_sparsity() and stop setting the internal o.pl field directly. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5d4f4a5 commit 1147c56

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

builtin/sparse-checkout.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,13 @@ static int update_working_directory(struct pattern_list *pl)
219219
o.dst_index = r->index;
220220
index_state_init(&o.result, r);
221221
o.skip_sparse_checkout = 0;
222-
o.pl = pl;
223222

224223
setup_work_tree();
225224

226225
repo_hold_locked_index(r, &lock_file, LOCK_DIE_ON_ERROR);
227226

228227
setup_unpack_trees_porcelain(&o, "sparse-checkout");
229-
result = update_sparsity(&o);
228+
result = update_sparsity(&o, pl);
230229
clear_unpack_trees_porcelain(&o);
231230

232231
if (result == UPDATE_SPARSITY_WARNINGS)

unpack-trees.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,10 +2091,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
20912091
*
20922092
* CE_NEW_SKIP_WORKTREE is used internally.
20932093
*/
2094-
enum update_sparsity_result update_sparsity(struct unpack_trees_options *o)
2094+
enum update_sparsity_result update_sparsity(struct unpack_trees_options *o,
2095+
struct pattern_list *pl)
20952096
{
20962097
enum update_sparsity_result ret = UPDATE_SPARSITY_SUCCESS;
2097-
struct pattern_list pl;
20982098
int i;
20992099
unsigned old_show_all_errors;
21002100
int free_pattern_list = 0;
@@ -2111,11 +2111,12 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o)
21112111
trace_performance_enter();
21122112

21132113
/* If we weren't given patterns, use the recorded ones */
2114-
if (!o->pl) {
2115-
memset(&pl, 0, sizeof(pl));
2114+
if (!pl) {
21162115
free_pattern_list = 1;
2117-
populate_from_existing_patterns(o, &pl);
2116+
pl = xcalloc(1, sizeof(*pl));
2117+
populate_from_existing_patterns(o, pl);
21182118
}
2119+
o->pl = pl;
21192120

21202121
/* Expand sparse directories as needed */
21212122
expand_index(o->src_index, o->pl);
@@ -2147,8 +2148,11 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o)
21472148

21482149
display_warning_msgs(o);
21492150
o->show_all_errors = old_show_all_errors;
2150-
if (free_pattern_list)
2151-
clear_pattern_list(&pl);
2151+
if (free_pattern_list) {
2152+
clear_pattern_list(pl);
2153+
free(pl);
2154+
o->pl = NULL;
2155+
}
21522156
trace_performance_leave("update_sparsity");
21532157
return ret;
21542158
}

unpack-trees.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ enum update_sparsity_result {
112112
UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES = -2
113113
};
114114

115-
enum update_sparsity_result update_sparsity(struct unpack_trees_options *options);
115+
enum update_sparsity_result update_sparsity(struct unpack_trees_options *options,
116+
struct pattern_list *pl);
116117

117118
int verify_uptodate(const struct cache_entry *ce,
118119
struct unpack_trees_options *o);

0 commit comments

Comments
 (0)