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 <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Sep 27, 2021 at 16:33 UTC c42e0b64093306d59372df288f9b4086290623f5
2 files changed +6 -3
unpack-trees.c
+5 -2
@@ -1692,9 +1692,12 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1692 static struct cache_entry *dfc;
1693 struct pattern_list pl;
1694 int free_pattern_list = 0;
1695 + struct dir_struct dir = DIR_INIT;
1696
1697 if (len > MAX_UNPACK_TREES)
1698 die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
1699 + if (o->dir)
1700 + BUG("o->dir is for internal use only");
1701
1702 trace_performance_enter();
1703 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
1709 }
1710
1711 if (!o->preserve_ignored) {
1709 - CALLOC_ARRAY(o->dir, 1);
1712 + o->dir = &dir;
1713 o->dir->flags |= DIR_SHOW_IGNORED;
1714 setup_standard_excludes(o->dir);
1715 }
@@ -1874,7 +1877,7 @@ done:
1877 clear_pattern_list(&pl);
1878 if (o->dir) {
1879 dir_clear(o->dir);
1877 - FREE_AND_NULL(o->dir);
1880 + o->dir = NULL;
1881 }
1882 trace2_region_leave("unpack_trees", "unpack_trees", the_repository);
1883 trace_performance_leave("unpack_trees");
unpack-trees.h
+1 -1
@@ -67,7 +67,6 @@ struct unpack_trees_options {
67 dry_run;
68 const char *prefix;
69 int cache_bottom;
70 - struct dir_struct *dir;
70 struct pathspec *pathspec;
71 merge_fn_t fn;
72 const char *msgs[NB_UNPACK_TREES_WARNING_TYPES];
@@ -89,6 +88,7 @@ struct unpack_trees_options {
88 struct index_state result;
89
90 struct pattern_list *pl; /* for internal use */
91 + struct dir_struct *dir; /* for internal use only */
92 struct checkout_metadata meta;
93 };
94