unpack_trees: start splitting internal fields from public API
This just splits the two fields already marked as internal-only into a separate internal struct. Future commits will add more fields that were meant to be internal-only but were not explicitly marked as such to the same struct. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Feb 27, 2023 at 15:28 UTC
576de3d95608df759c1f09e84f4ce1cea3c404d4
2 files changed
+25
-22
unpack-trees.c
+20
-20
@@ -1809,7 +1809,7 @@ static void populate_from_existing_patterns(struct unpack_trees_options *o,
1809
if (get_sparse_checkout_patterns(pl) < 0)
1810
o->skip_sparse_checkout = 1;
1811
else
1812
- o->pl = pl;
1812
+ o->internal.pl = pl;
1813
}
1814
1815
static void update_sparsity_for_prefix(const char *prefix,
@@ -1871,10 +1871,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1871
1872
if (len > MAX_UNPACK_TREES)
1873
die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
1874
- if (o->dir)
1875
- BUG("o->dir is for internal use only");
1876
- if (o->pl)
1877
- BUG("o->pl is for internal use only");
1874
+ if (o->internal.dir)
1875
+ BUG("o->internal.dir is for internal use only");
1876
+ if (o->internal.pl)
1877
+ BUG("o->internal.pl is for internal use only");
1878
1879
trace_performance_enter();
1880
trace2_region_enter("unpack_trees", "unpack_trees", the_repository);
@@ -1891,9 +1891,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1891
BUG("UNPACK_RESET_OVERWRITE_UNTRACKED incompatible with preserved ignored files");
1892
1893
if (!o->preserve_ignored) {
1894
- o->dir = &dir;
1895
- o->dir->flags |= DIR_SHOW_IGNORED;
1896
- setup_standard_excludes(o->dir);
1894
+ o->internal.dir = &dir;
1895
+ o->internal.dir->flags |= DIR_SHOW_IGNORED;
1896
+ setup_standard_excludes(o->internal.dir);
1897
}
1898
1899
if (o->prefix)
@@ -1943,7 +1943,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1943
* Sparse checkout loop #1: set NEW_SKIP_WORKTREE on existing entries
1944
*/
1945
if (!o->skip_sparse_checkout)
1946
- mark_new_skip_worktree(o->pl, o->src_index, 0,
1946
+ mark_new_skip_worktree(o->internal.pl, o->src_index, 0,
1947
CE_NEW_SKIP_WORKTREE, o->verbose_update);
1948
1949
if (!dfc)
@@ -2009,7 +2009,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
2009
* If they will have NEW_SKIP_WORKTREE, also set CE_SKIP_WORKTREE
2010
* so apply_sparse_checkout() won't attempt to remove it from worktree
2011
*/
2012
- mark_new_skip_worktree(o->pl, &o->result,
2012
+ mark_new_skip_worktree(o->internal.pl, &o->result,
2013
CE_ADDED, CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE,
2014
o->verbose_update);
2015
@@ -2067,9 +2067,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
2067
done:
2068
if (free_pattern_list)
2069
clear_pattern_list(&pl);
2070
- if (o->dir) {
2071
- dir_clear(o->dir);
2072
- o->dir = NULL;
2070
+ if (o->internal.dir) {
2071
+ dir_clear(o->internal.dir);
2072
+ o->internal.dir = NULL;
2073
}
2074
trace2_region_leave("unpack_trees", "unpack_trees", the_repository);
2075
trace_performance_leave("unpack_trees");
@@ -2117,14 +2117,14 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o,
2117
pl = xcalloc(1, sizeof(*pl));
2118
populate_from_existing_patterns(o, pl);
2119
}
2120
- o->pl = pl;
2120
+ o->internal.pl = pl;
2121
2122
/* Expand sparse directories as needed */
2123
- expand_index(o->src_index, o->pl);
2123
+ expand_index(o->src_index, o->internal.pl);
2124
2125
/* Set NEW_SKIP_WORKTREE on existing entries. */
2126
mark_all_ce_unused(o->src_index);
2127
- mark_new_skip_worktree(o->pl, o->src_index, 0,
2127
+ mark_new_skip_worktree(o->internal.pl, o->src_index, 0,
2128
CE_NEW_SKIP_WORKTREE, o->verbose_update);
2129
2130
/* Then loop over entries and update/remove as needed */
@@ -2152,7 +2152,7 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o,
2152
if (free_pattern_list) {
2153
clear_pattern_list(pl);
2154
free(pl);
2155
- o->pl = NULL;
2155
+ o->internal.pl = NULL;
2156
}
2157
trace_performance_leave("update_sparsity");
2158
return ret;
@@ -2340,7 +2340,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
2340
pathbuf = xstrfmt("%.*s/", namelen, ce->name);
2341
2342
memset(&d, 0, sizeof(d));
2343
- if (o->dir)
2343
+ if (o->internal.dir)
2344
setup_standard_excludes(&d);
2345
i = read_directory(&d, o->src_index, pathbuf, namelen+1, NULL);
2346
dir_clear(&d);
@@ -2395,8 +2395,8 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
2395
if (ignore_case && icase_exists(o, name, len, st))
2396
return 0;
2397
2398
- if (o->dir &&
2399
- is_excluded(o->dir, o->src_index, name, &dtype))
2398
+ if (o->internal.dir &&
2399
+ is_excluded(o->internal.dir, o->src_index, name, &dtype))
2400
/*
2401
* ce->name is explicitly excluded, so it is Ok to
2402
* overwrite it.
unpack-trees.h
+5
-2
@@ -97,9 +97,12 @@ struct unpack_trees_options {
97
struct index_state *src_index;
98
struct index_state result;
99
100
- struct pattern_list *pl; /* for internal use */
101
- struct dir_struct *dir; /* for internal use only */
100
struct checkout_metadata meta;
101
+
102
+ struct unpack_trees_options_internal {
103
+ struct pattern_list *pl;
104
+ struct dir_struct *dir;
105
+ } internal;
106
};
107
108
int unpack_trees(unsigned n, struct tree_desc *t,