Skip to content

Commit f17d232

Browse files
committed
Merge branch 'en/dir-api-cleanup'
Code clean-up to clarify directory traversal API. * en/dir-api-cleanup: unpack-trees: add usage notices around df_conflict_entry unpack-trees: special case read-tree debugging as internal usage unpack-trees: rewrap a few overlong lines from previous patch unpack-trees: mark fields only used internally as internal unpack_trees: start splitting internal fields from public API sparse-checkout: avoid using internal API of unpack-trees, take 2 sparse-checkout: avoid using internal API of unpack-trees unpack-trees: clean up some flow control dir: mark output only fields of dir_struct as such dir: add a usage note to exclude_per_dir dir: separate public from internal portion of dir_struct unpack-trees: heed requests to overwrite ignored files t2021: fix platform-specific leftover cruft
2 parents 2d019f4 + f297424 commit f17d232

File tree

7 files changed

+292
-251
lines changed

7 files changed

+292
-251
lines changed

builtin/read-tree.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ static int debug_merge(const struct cache_entry * const *stages,
8787
{
8888
int i;
8989

90-
printf("* %d-way merge\n", o->merge_size);
90+
printf("* %d-way merge\n", o->internal.merge_size);
9191
debug_stage("index", stages[0], o);
92-
for (i = 1; i <= o->merge_size; i++) {
92+
for (i = 1; i <= o->internal.merge_size; i++) {
9393
char buf[24];
9494
xsnprintf(buf, sizeof(buf), "ent#%d", i);
9595
debug_stage(buf, stages[i], o);
@@ -144,7 +144,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
144144
OPT__DRY_RUN(&opts.dry_run, N_("don't update the index or the work tree")),
145145
OPT_BOOL(0, "no-sparse-checkout", &opts.skip_sparse_checkout,
146146
N_("skip applying sparse checkout filter")),
147-
OPT_BOOL(0, "debug-unpack", &opts.debug_unpack,
147+
OPT_BOOL(0, "debug-unpack", &opts.internal.debug_unpack,
148148
N_("debug unpack-trees")),
149149
OPT_CALLBACK_F(0, "recurse-submodules", NULL,
150150
"checkout", "control recursive updating of submodules",
@@ -247,7 +247,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
247247
opts.head_idx = 1;
248248
}
249249

250-
if (opts.debug_unpack)
250+
if (opts.internal.debug_unpack)
251251
opts.fn = debug_merge;
252252

253253
/* If we're going to prime_cache_tree later, skip cache tree update */
@@ -263,7 +263,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
263263
if (unpack_trees(nr_trees, t, &opts))
264264
return 128;
265265

266-
if (opts.debug_unpack || opts.dry_run)
266+
if (opts.internal.debug_unpack || opts.dry_run)
267267
return 0; /* do not write the index out */
268268

269269
/*

builtin/sparse-checkout.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,14 @@ static int update_working_directory(struct pattern_list *pl)
217217
o.head_idx = -1;
218218
o.src_index = r->index;
219219
o.dst_index = r->index;
220-
index_state_init(&o.result, r);
221220
o.skip_sparse_checkout = 0;
222-
o.pl = pl;
223221

224222
setup_work_tree();
225223

226224
repo_hold_locked_index(r, &lock_file, LOCK_DIE_ON_ERROR);
227225

228226
setup_unpack_trees_porcelain(&o, "sparse-checkout");
229-
result = update_sparsity(&o);
227+
result = update_sparsity(&o, pl);
230228
clear_unpack_trees_porcelain(&o);
231229

232230
if (result == UPDATE_SPARSITY_WARNINGS)

dir.c

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ struct pattern_list *add_pattern_list(struct dir_struct *dir,
11901190
struct pattern_list *pl;
11911191
struct exclude_list_group *group;
11921192

1193-
group = &dir->exclude_list_group[group_type];
1193+
group = &dir->internal.exclude_list_group[group_type];
11941194
ALLOC_GROW(group->pl, group->nr + 1, group->alloc);
11951195
pl = &group->pl[group->nr++];
11961196
memset(pl, 0, sizeof(*pl));
@@ -1211,15 +1211,15 @@ static void add_patterns_from_file_1(struct dir_struct *dir, const char *fname,
12111211
* differently when dir->untracked is non-NULL.
12121212
*/
12131213
if (!dir->untracked)
1214-
dir->unmanaged_exclude_files++;
1214+
dir->internal.unmanaged_exclude_files++;
12151215
pl = add_pattern_list(dir, EXC_FILE, fname);
12161216
if (add_patterns(fname, "", 0, pl, NULL, 0, oid_stat) < 0)
12171217
die(_("cannot use %s as an exclude file"), fname);
12181218
}
12191219

12201220
void add_patterns_from_file(struct dir_struct *dir, const char *fname)
12211221
{
1222-
dir->unmanaged_exclude_files++; /* see validate_untracked_cache() */
1222+
dir->internal.unmanaged_exclude_files++; /* see validate_untracked_cache() */
12231223
add_patterns_from_file_1(dir, fname, NULL);
12241224
}
12251225

@@ -1519,7 +1519,7 @@ static struct path_pattern *last_matching_pattern_from_lists(
15191519
struct exclude_list_group *group;
15201520
struct path_pattern *pattern;
15211521
for (i = EXC_CMDL; i <= EXC_FILE; i++) {
1522-
group = &dir->exclude_list_group[i];
1522+
group = &dir->internal.exclude_list_group[i];
15231523
for (j = group->nr - 1; j >= 0; j--) {
15241524
pattern = last_matching_pattern_from_list(
15251525
pathname, pathlen, basename, dtype_p,
@@ -1545,41 +1545,41 @@ static void prep_exclude(struct dir_struct *dir,
15451545
struct untracked_cache_dir *untracked;
15461546
int current;
15471547

1548-
group = &dir->exclude_list_group[EXC_DIRS];
1548+
group = &dir->internal.exclude_list_group[EXC_DIRS];
15491549

15501550
/*
15511551
* Pop the exclude lists from the EXCL_DIRS exclude_list_group
15521552
* which originate from directories not in the prefix of the
15531553
* path being checked.
15541554
*/
1555-
while ((stk = dir->exclude_stack) != NULL) {
1555+
while ((stk = dir->internal.exclude_stack) != NULL) {
15561556
if (stk->baselen <= baselen &&
1557-
!strncmp(dir->basebuf.buf, base, stk->baselen))
1557+
!strncmp(dir->internal.basebuf.buf, base, stk->baselen))
15581558
break;
1559-
pl = &group->pl[dir->exclude_stack->exclude_ix];
1560-
dir->exclude_stack = stk->prev;
1561-
dir->pattern = NULL;
1559+
pl = &group->pl[dir->internal.exclude_stack->exclude_ix];
1560+
dir->internal.exclude_stack = stk->prev;
1561+
dir->internal.pattern = NULL;
15621562
free((char *)pl->src); /* see strbuf_detach() below */
15631563
clear_pattern_list(pl);
15641564
free(stk);
15651565
group->nr--;
15661566
}
15671567

15681568
/* Skip traversing into sub directories if the parent is excluded */
1569-
if (dir->pattern)
1569+
if (dir->internal.pattern)
15701570
return;
15711571

15721572
/*
15731573
* Lazy initialization. All call sites currently just
15741574
* memset(dir, 0, sizeof(*dir)) before use. Changing all of
15751575
* them seems lots of work for little benefit.
15761576
*/
1577-
if (!dir->basebuf.buf)
1578-
strbuf_init(&dir->basebuf, PATH_MAX);
1577+
if (!dir->internal.basebuf.buf)
1578+
strbuf_init(&dir->internal.basebuf, PATH_MAX);
15791579

15801580
/* Read from the parent directories and push them down. */
15811581
current = stk ? stk->baselen : -1;
1582-
strbuf_setlen(&dir->basebuf, current < 0 ? 0 : current);
1582+
strbuf_setlen(&dir->internal.basebuf, current < 0 ? 0 : current);
15831583
if (dir->untracked)
15841584
untracked = stk ? stk->ucd : dir->untracked->root;
15851585
else
@@ -1599,32 +1599,33 @@ static void prep_exclude(struct dir_struct *dir,
15991599
die("oops in prep_exclude");
16001600
cp++;
16011601
untracked =
1602-
lookup_untracked(dir->untracked, untracked,
1602+
lookup_untracked(dir->untracked,
1603+
untracked,
16031604
base + current,
16041605
cp - base - current);
16051606
}
1606-
stk->prev = dir->exclude_stack;
1607+
stk->prev = dir->internal.exclude_stack;
16071608
stk->baselen = cp - base;
16081609
stk->exclude_ix = group->nr;
16091610
stk->ucd = untracked;
16101611
pl = add_pattern_list(dir, EXC_DIRS, NULL);
1611-
strbuf_add(&dir->basebuf, base + current, stk->baselen - current);
1612-
assert(stk->baselen == dir->basebuf.len);
1612+
strbuf_add(&dir->internal.basebuf, base + current, stk->baselen - current);
1613+
assert(stk->baselen == dir->internal.basebuf.len);
16131614

16141615
/* Abort if the directory is excluded */
16151616
if (stk->baselen) {
16161617
int dt = DT_DIR;
1617-
dir->basebuf.buf[stk->baselen - 1] = 0;
1618-
dir->pattern = last_matching_pattern_from_lists(dir,
1618+
dir->internal.basebuf.buf[stk->baselen - 1] = 0;
1619+
dir->internal.pattern = last_matching_pattern_from_lists(dir,
16191620
istate,
1620-
dir->basebuf.buf, stk->baselen - 1,
1621-
dir->basebuf.buf + current, &dt);
1622-
dir->basebuf.buf[stk->baselen - 1] = '/';
1623-
if (dir->pattern &&
1624-
dir->pattern->flags & PATTERN_FLAG_NEGATIVE)
1625-
dir->pattern = NULL;
1626-
if (dir->pattern) {
1627-
dir->exclude_stack = stk;
1621+
dir->internal.basebuf.buf, stk->baselen - 1,
1622+
dir->internal.basebuf.buf + current, &dt);
1623+
dir->internal.basebuf.buf[stk->baselen - 1] = '/';
1624+
if (dir->internal.pattern &&
1625+
dir->internal.pattern->flags & PATTERN_FLAG_NEGATIVE)
1626+
dir->internal.pattern = NULL;
1627+
if (dir->internal.pattern) {
1628+
dir->internal.exclude_stack = stk;
16281629
return;
16291630
}
16301631
}
@@ -1647,15 +1648,15 @@ static void prep_exclude(struct dir_struct *dir,
16471648
*/
16481649
!is_null_oid(&untracked->exclude_oid))) {
16491650
/*
1650-
* dir->basebuf gets reused by the traversal, but we
1651-
* need fname to remain unchanged to ensure the src
1652-
* member of each struct path_pattern correctly
1651+
* dir->internal.basebuf gets reused by the traversal,
1652+
* but we need fname to remain unchanged to ensure the
1653+
* src member of each struct path_pattern correctly
16531654
* back-references its source file. Other invocations
16541655
* of add_pattern_list provide stable strings, so we
16551656
* strbuf_detach() and free() here in the caller.
16561657
*/
16571658
struct strbuf sb = STRBUF_INIT;
1658-
strbuf_addbuf(&sb, &dir->basebuf);
1659+
strbuf_addbuf(&sb, &dir->internal.basebuf);
16591660
strbuf_addstr(&sb, dir->exclude_per_dir);
16601661
pl->src = strbuf_detach(&sb, NULL);
16611662
add_patterns(pl->src, pl->src, stk->baselen, pl, istate,
@@ -1681,10 +1682,10 @@ static void prep_exclude(struct dir_struct *dir,
16811682
invalidate_gitignore(dir->untracked, untracked);
16821683
oidcpy(&untracked->exclude_oid, &oid_stat.oid);
16831684
}
1684-
dir->exclude_stack = stk;
1685+
dir->internal.exclude_stack = stk;
16851686
current = stk->baselen;
16861687
}
1687-
strbuf_setlen(&dir->basebuf, baselen);
1688+
strbuf_setlen(&dir->internal.basebuf, baselen);
16881689
}
16891690

16901691
/*
@@ -1704,8 +1705,8 @@ struct path_pattern *last_matching_pattern(struct dir_struct *dir,
17041705

17051706
prep_exclude(dir, istate, pathname, basename-pathname);
17061707

1707-
if (dir->pattern)
1708-
return dir->pattern;
1708+
if (dir->internal.pattern)
1709+
return dir->internal.pattern;
17091710

17101711
return last_matching_pattern_from_lists(dir, istate, pathname, pathlen,
17111712
basename, dtype_p);
@@ -1742,7 +1743,7 @@ static struct dir_entry *dir_add_name(struct dir_struct *dir,
17421743
if (index_file_exists(istate, pathname, len, ignore_case))
17431744
return NULL;
17441745

1745-
ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc);
1746+
ALLOC_GROW(dir->entries, dir->nr+1, dir->internal.alloc);
17461747
return dir->entries[dir->nr++] = dir_entry_new(pathname, len);
17471748
}
17481749

@@ -1753,7 +1754,7 @@ struct dir_entry *dir_add_ignored(struct dir_struct *dir,
17531754
if (!index_name_is_other(istate, pathname, len))
17541755
return NULL;
17551756

1756-
ALLOC_GROW(dir->ignored, dir->ignored_nr+1, dir->ignored_alloc);
1757+
ALLOC_GROW(dir->ignored, dir->ignored_nr+1, dir->internal.ignored_alloc);
17571758
return dir->ignored[dir->ignored_nr++] = dir_entry_new(pathname, len);
17581759
}
17591760

@@ -2569,7 +2570,7 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
25692570

25702571
if (open_cached_dir(&cdir, dir, untracked, istate, &path, check_only))
25712572
goto out;
2572-
dir->visited_directories++;
2573+
dir->internal.visited_directories++;
25732574

25742575
if (untracked)
25752576
untracked->check_only = !!check_only;
@@ -2578,15 +2579,16 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
25782579
/* check how the file or directory should be treated */
25792580
state = treat_path(dir, untracked, &cdir, istate, &path,
25802581
baselen, pathspec);
2581-
dir->visited_paths++;
2582+
dir->internal.visited_paths++;
25822583

25832584
if (state > dir_state)
25842585
dir_state = state;
25852586

25862587
/* recurse into subdir if instructed by treat_path */
25872588
if (state == path_recurse) {
25882589
struct untracked_cache_dir *ud;
2589-
ud = lookup_untracked(dir->untracked, untracked,
2590+
ud = lookup_untracked(dir->untracked,
2591+
untracked,
25902592
path.buf + baselen,
25912593
path.len - baselen);
25922594
subdir_state =
@@ -2846,7 +2848,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
28462848
* condition also catches running setup_standard_excludes()
28472849
* before setting dir->untracked!
28482850
*/
2849-
if (dir->unmanaged_exclude_files)
2851+
if (dir->internal.unmanaged_exclude_files)
28502852
return NULL;
28512853

28522854
/*
@@ -2875,7 +2877,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
28752877
* EXC_CMDL is not considered in the cache. If people set it,
28762878
* skip the cache.
28772879
*/
2878-
if (dir->exclude_list_group[EXC_CMDL].nr)
2880+
if (dir->internal.exclude_list_group[EXC_CMDL].nr)
28792881
return NULL;
28802882

28812883
if (!ident_in_untracked(dir->untracked)) {
@@ -2935,15 +2937,15 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
29352937

29362938
/* Validate $GIT_DIR/info/exclude and core.excludesfile */
29372939
root = dir->untracked->root;
2938-
if (!oideq(&dir->ss_info_exclude.oid,
2940+
if (!oideq(&dir->internal.ss_info_exclude.oid,
29392941
&dir->untracked->ss_info_exclude.oid)) {
29402942
invalidate_gitignore(dir->untracked, root);
2941-
dir->untracked->ss_info_exclude = dir->ss_info_exclude;
2943+
dir->untracked->ss_info_exclude = dir->internal.ss_info_exclude;
29422944
}
2943-
if (!oideq(&dir->ss_excludes_file.oid,
2945+
if (!oideq(&dir->internal.ss_excludes_file.oid,
29442946
&dir->untracked->ss_excludes_file.oid)) {
29452947
invalidate_gitignore(dir->untracked, root);
2946-
dir->untracked->ss_excludes_file = dir->ss_excludes_file;
2948+
dir->untracked->ss_excludes_file = dir->internal.ss_excludes_file;
29472949
}
29482950

29492951
/* Make sure this directory is not dropped out at saving phase */
@@ -2969,9 +2971,9 @@ static void emit_traversal_statistics(struct dir_struct *dir,
29692971
}
29702972

29712973
trace2_data_intmax("read_directory", repo,
2972-
"directories-visited", dir->visited_directories);
2974+
"directories-visited", dir->internal.visited_directories);
29732975
trace2_data_intmax("read_directory", repo,
2974-
"paths-visited", dir->visited_paths);
2976+
"paths-visited", dir->internal.visited_paths);
29752977

29762978
if (!dir->untracked)
29772979
return;
@@ -2993,8 +2995,8 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
29932995
struct untracked_cache_dir *untracked;
29942996

29952997
trace2_region_enter("dir", "read_directory", istate->repo);
2996-
dir->visited_paths = 0;
2997-
dir->visited_directories = 0;
2998+
dir->internal.visited_paths = 0;
2999+
dir->internal.visited_directories = 0;
29983000

29993001
if (has_symlink_leading_path(path, len)) {
30003002
trace2_region_leave("dir", "read_directory", istate->repo);
@@ -3342,14 +3344,14 @@ void setup_standard_excludes(struct dir_struct *dir)
33423344
excludes_file = xdg_config_home("ignore");
33433345
if (excludes_file && !access_or_warn(excludes_file, R_OK, 0))
33443346
add_patterns_from_file_1(dir, excludes_file,
3345-
dir->untracked ? &dir->ss_excludes_file : NULL);
3347+
dir->untracked ? &dir->internal.ss_excludes_file : NULL);
33463348

33473349
/* per repository user preference */
33483350
if (startup_info->have_repository) {
33493351
const char *path = git_path_info_exclude();
33503352
if (!access_or_warn(path, R_OK, 0))
33513353
add_patterns_from_file_1(dir, path,
3352-
dir->untracked ? &dir->ss_info_exclude : NULL);
3354+
dir->untracked ? &dir->internal.ss_info_exclude : NULL);
33533355
}
33543356
}
33553357

@@ -3405,7 +3407,7 @@ void dir_clear(struct dir_struct *dir)
34053407
struct dir_struct new = DIR_INIT;
34063408

34073409
for (i = EXC_CMDL; i <= EXC_FILE; i++) {
3408-
group = &dir->exclude_list_group[i];
3410+
group = &dir->internal.exclude_list_group[i];
34093411
for (j = 0; j < group->nr; j++) {
34103412
pl = &group->pl[j];
34113413
if (i == EXC_DIRS)
@@ -3422,13 +3424,13 @@ void dir_clear(struct dir_struct *dir)
34223424
free(dir->ignored);
34233425
free(dir->entries);
34243426

3425-
stk = dir->exclude_stack;
3427+
stk = dir->internal.exclude_stack;
34263428
while (stk) {
34273429
struct exclude_stack *prev = stk->prev;
34283430
free(stk);
34293431
stk = prev;
34303432
}
3431-
strbuf_release(&dir->basebuf);
3433+
strbuf_release(&dir->internal.basebuf);
34323434

34333435
memcpy(dir, &new, sizeof(*dir));
34343436
}

0 commit comments

Comments
 (0)