Skip to content

Commit

Permalink
Merge branch 'en/dir-api-cleanup' into seen
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gitster committed Feb 24, 2023
2 parents 4b47413 + 8217533 commit f556130
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 250 deletions.
10 changes: 5 additions & 5 deletions builtin/read-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ static int debug_merge(const struct cache_entry * const *stages,
{
int i;

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

if (opts.debug_unpack)
if (opts.internal.debug_unpack)
opts.fn = debug_merge;

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

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

/*
Expand Down
4 changes: 1 addition & 3 deletions builtin/sparse-checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,14 @@ static int update_working_directory(struct pattern_list *pl)
o.head_idx = -1;
o.src_index = r->index;
o.dst_index = r->index;
index_state_init(&o.result, r);
o.skip_sparse_checkout = 0;
o.pl = pl;

setup_work_tree();

repo_hold_locked_index(r, &lock_file, LOCK_DIE_ON_ERROR);

setup_unpack_trees_porcelain(&o, "sparse-checkout");
result = update_sparsity(&o);
result = update_sparsity(&o, pl);
clear_unpack_trees_porcelain(&o);

if (result == UPDATE_SPARSITY_WARNINGS)
Expand Down
114 changes: 58 additions & 56 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ struct pattern_list *add_pattern_list(struct dir_struct *dir,
struct pattern_list *pl;
struct exclude_list_group *group;

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

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

Expand Down Expand Up @@ -1519,7 +1519,7 @@ static struct path_pattern *last_matching_pattern_from_lists(
struct exclude_list_group *group;
struct path_pattern *pattern;
for (i = EXC_CMDL; i <= EXC_FILE; i++) {
group = &dir->exclude_list_group[i];
group = &dir->internal.exclude_list_group[i];
for (j = group->nr - 1; j >= 0; j--) {
pattern = last_matching_pattern_from_list(
pathname, pathlen, basename, dtype_p,
Expand All @@ -1545,41 +1545,41 @@ static void prep_exclude(struct dir_struct *dir,
struct untracked_cache_dir *untracked;
int current;

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

/*
* Pop the exclude lists from the EXCL_DIRS exclude_list_group
* which originate from directories not in the prefix of the
* path being checked.
*/
while ((stk = dir->exclude_stack) != NULL) {
while ((stk = dir->internal.exclude_stack) != NULL) {
if (stk->baselen <= baselen &&
!strncmp(dir->basebuf.buf, base, stk->baselen))
!strncmp(dir->internal.basebuf.buf, base, stk->baselen))
break;
pl = &group->pl[dir->exclude_stack->exclude_ix];
dir->exclude_stack = stk->prev;
dir->pattern = NULL;
pl = &group->pl[dir->internal.exclude_stack->exclude_ix];
dir->internal.exclude_stack = stk->prev;
dir->internal.pattern = NULL;
free((char *)pl->src); /* see strbuf_detach() below */
clear_pattern_list(pl);
free(stk);
group->nr--;
}

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

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

/* Read from the parent directories and push them down. */
current = stk ? stk->baselen : -1;
strbuf_setlen(&dir->basebuf, current < 0 ? 0 : current);
strbuf_setlen(&dir->internal.basebuf, current < 0 ? 0 : current);
if (dir->untracked)
untracked = stk ? stk->ucd : dir->untracked->root;
else
Expand All @@ -1599,32 +1599,33 @@ static void prep_exclude(struct dir_struct *dir,
die("oops in prep_exclude");
cp++;
untracked =
lookup_untracked(dir->untracked, untracked,
lookup_untracked(dir->untracked,
untracked,
base + current,
cp - base - current);
}
stk->prev = dir->exclude_stack;
stk->prev = dir->internal.exclude_stack;
stk->baselen = cp - base;
stk->exclude_ix = group->nr;
stk->ucd = untracked;
pl = add_pattern_list(dir, EXC_DIRS, NULL);
strbuf_add(&dir->basebuf, base + current, stk->baselen - current);
assert(stk->baselen == dir->basebuf.len);
strbuf_add(&dir->internal.basebuf, base + current, stk->baselen - current);
assert(stk->baselen == dir->internal.basebuf.len);

/* Abort if the directory is excluded */
if (stk->baselen) {
int dt = DT_DIR;
dir->basebuf.buf[stk->baselen - 1] = 0;
dir->pattern = last_matching_pattern_from_lists(dir,
dir->internal.basebuf.buf[stk->baselen - 1] = 0;
dir->internal.pattern = last_matching_pattern_from_lists(dir,
istate,
dir->basebuf.buf, stk->baselen - 1,
dir->basebuf.buf + current, &dt);
dir->basebuf.buf[stk->baselen - 1] = '/';
if (dir->pattern &&
dir->pattern->flags & PATTERN_FLAG_NEGATIVE)
dir->pattern = NULL;
if (dir->pattern) {
dir->exclude_stack = stk;
dir->internal.basebuf.buf, stk->baselen - 1,
dir->internal.basebuf.buf + current, &dt);
dir->internal.basebuf.buf[stk->baselen - 1] = '/';
if (dir->internal.pattern &&
dir->internal.pattern->flags & PATTERN_FLAG_NEGATIVE)
dir->internal.pattern = NULL;
if (dir->internal.pattern) {
dir->internal.exclude_stack = stk;
return;
}
}
Expand All @@ -1647,15 +1648,15 @@ static void prep_exclude(struct dir_struct *dir,
*/
!is_null_oid(&untracked->exclude_oid))) {
/*
* dir->basebuf gets reused by the traversal, but we
* need fname to remain unchanged to ensure the src
* member of each struct path_pattern correctly
* dir->internal.basebuf gets reused by the traversal,
* but we need fname to remain unchanged to ensure the
* src member of each struct path_pattern correctly
* back-references its source file. Other invocations
* of add_pattern_list provide stable strings, so we
* strbuf_detach() and free() here in the caller.
*/
struct strbuf sb = STRBUF_INIT;
strbuf_addbuf(&sb, &dir->basebuf);
strbuf_addbuf(&sb, &dir->internal.basebuf);
strbuf_addstr(&sb, dir->exclude_per_dir);
pl->src = strbuf_detach(&sb, NULL);
add_patterns(pl->src, pl->src, stk->baselen, pl, istate,
Expand All @@ -1681,10 +1682,10 @@ static void prep_exclude(struct dir_struct *dir,
invalidate_gitignore(dir->untracked, untracked);
oidcpy(&untracked->exclude_oid, &oid_stat.oid);
}
dir->exclude_stack = stk;
dir->internal.exclude_stack = stk;
current = stk->baselen;
}
strbuf_setlen(&dir->basebuf, baselen);
strbuf_setlen(&dir->internal.basebuf, baselen);
}

/*
Expand All @@ -1704,8 +1705,8 @@ struct path_pattern *last_matching_pattern(struct dir_struct *dir,

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

if (dir->pattern)
return dir->pattern;
if (dir->internal.pattern)
return dir->internal.pattern;

return last_matching_pattern_from_lists(dir, istate, pathname, pathlen,
basename, dtype_p);
Expand Down Expand Up @@ -1742,7 +1743,7 @@ static struct dir_entry *dir_add_name(struct dir_struct *dir,
if (index_file_exists(istate, pathname, len, ignore_case))
return NULL;

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

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

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

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

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

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

if (state > dir_state)
dir_state = state;

/* recurse into subdir if instructed by treat_path */
if (state == path_recurse) {
struct untracked_cache_dir *ud;
ud = lookup_untracked(dir->untracked, untracked,
ud = lookup_untracked(dir->untracked,
untracked,
path.buf + baselen,
path.len - baselen);
subdir_state =
Expand Down Expand Up @@ -2846,7 +2848,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
* condition also catches running setup_standard_excludes()
* before setting dir->untracked!
*/
if (dir->unmanaged_exclude_files)
if (dir->internal.unmanaged_exclude_files)
return NULL;

/*
Expand Down Expand Up @@ -2875,7 +2877,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
* EXC_CMDL is not considered in the cache. If people set it,
* skip the cache.
*/
if (dir->exclude_list_group[EXC_CMDL].nr)
if (dir->internal.exclude_list_group[EXC_CMDL].nr)
return NULL;

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

/* Validate $GIT_DIR/info/exclude and core.excludesfile */
root = dir->untracked->root;
if (!oideq(&dir->ss_info_exclude.oid,
if (!oideq(&dir->internal.ss_info_exclude.oid,
&dir->untracked->ss_info_exclude.oid)) {
invalidate_gitignore(dir->untracked, root);
dir->untracked->ss_info_exclude = dir->ss_info_exclude;
dir->untracked->ss_info_exclude = dir->internal.ss_info_exclude;
}
if (!oideq(&dir->ss_excludes_file.oid,
if (!oideq(&dir->internal.ss_excludes_file.oid,
&dir->untracked->ss_excludes_file.oid)) {
invalidate_gitignore(dir->untracked, root);
dir->untracked->ss_excludes_file = dir->ss_excludes_file;
dir->untracked->ss_excludes_file = dir->internal.ss_excludes_file;
}

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

trace2_data_intmax("read_directory", repo,
"directories-visited", dir->visited_directories);
"directories-visited", dir->internal.visited_directories);
trace2_data_intmax("read_directory", repo,
"paths-visited", dir->visited_paths);
"paths-visited", dir->internal.visited_paths);

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

trace2_region_enter("dir", "read_directory", istate->repo);
dir->visited_paths = 0;
dir->visited_directories = 0;
dir->internal.visited_paths = 0;
dir->internal.visited_directories = 0;

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

/* per repository user preference */
if (startup_info->have_repository) {
const char *path = git_path_info_exclude();
if (!access_or_warn(path, R_OK, 0))
add_patterns_from_file_1(dir, path,
dir->untracked ? &dir->ss_info_exclude : NULL);
dir->untracked ? &dir->internal.ss_info_exclude : NULL);
}
}

Expand Down Expand Up @@ -3405,7 +3407,7 @@ void dir_clear(struct dir_struct *dir)
struct dir_struct new = DIR_INIT;

for (i = EXC_CMDL; i <= EXC_FILE; i++) {
group = &dir->exclude_list_group[i];
group = &dir->internal.exclude_list_group[i];
for (j = 0; j < group->nr; j++) {
pl = &group->pl[j];
if (i == EXC_DIRS)
Expand All @@ -3422,13 +3424,13 @@ void dir_clear(struct dir_struct *dir)
free(dir->ignored);
free(dir->entries);

stk = dir->exclude_stack;
stk = dir->internal.exclude_stack;
while (stk) {
struct exclude_stack *prev = stk->prev;
free(stk);
stk = prev;
}
strbuf_release(&dir->basebuf);
strbuf_release(&dir->internal.basebuf);

memcpy(dir, &new, sizeof(*dir));
}
Expand Down

0 comments on commit f556130

Please sign in to comment.