Skip to content

Commit c42e0b6

Browse files
newrengitster
authored andcommitted
unpack-trees: make dir an internal-only struct
Avoid accidental misuse or confusion over ownership by clearly making unpack_trees_options.dir an internal-only variable. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 04988c8 commit c42e0b6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

unpack-trees.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,9 +1692,12 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
16921692
static struct cache_entry *dfc;
16931693
struct pattern_list pl;
16941694
int free_pattern_list = 0;
1695+
struct dir_struct dir = DIR_INIT;
16951696

16961697
if (len > MAX_UNPACK_TREES)
16971698
die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
1699+
if (o->dir)
1700+
BUG("o->dir is for internal use only");
16981701

16991702
trace_performance_enter();
17001703
trace2_region_enter("unpack_trees", "unpack_trees", the_repository);
@@ -1706,7 +1709,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
17061709
}
17071710

17081711
if (!o->preserve_ignored) {
1709-
CALLOC_ARRAY(o->dir, 1);
1712+
o->dir = &dir;
17101713
o->dir->flags |= DIR_SHOW_IGNORED;
17111714
setup_standard_excludes(o->dir);
17121715
}
@@ -1874,7 +1877,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
18741877
clear_pattern_list(&pl);
18751878
if (o->dir) {
18761879
dir_clear(o->dir);
1877-
FREE_AND_NULL(o->dir);
1880+
o->dir = NULL;
18781881
}
18791882
trace2_region_leave("unpack_trees", "unpack_trees", the_repository);
18801883
trace_performance_leave("unpack_trees");

unpack-trees.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ struct unpack_trees_options {
6767
dry_run;
6868
const char *prefix;
6969
int cache_bottom;
70-
struct dir_struct *dir;
7170
struct pathspec *pathspec;
7271
merge_fn_t fn;
7372
const char *msgs[NB_UNPACK_TREES_WARNING_TYPES];
@@ -89,6 +88,7 @@ struct unpack_trees_options {
8988
struct index_state result;
9089

9190
struct pattern_list *pl; /* for internal use */
91+
struct dir_struct *dir; /* for internal use only */
9292
struct checkout_metadata meta;
9393
};
9494

0 commit comments

Comments
 (0)