mirror of
https://github.com/git/git
synced 2024-08-27 03:29:21 +00:00
Turn the flags in struct dir_struct into a single variable
By having flags represented as bits in the new member variable 'flags', it will be easier to use parse_options when dir_struct is involved. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
81d3fe9f48
commit
7c4c97c0ac
|
@ -104,7 +104,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
|
||||||
/* Set up the default git porcelain excludes */
|
/* Set up the default git porcelain excludes */
|
||||||
memset(dir, 0, sizeof(*dir));
|
memset(dir, 0, sizeof(*dir));
|
||||||
if (!ignored_too) {
|
if (!ignored_too) {
|
||||||
dir->collect_ignored = 1;
|
dir->flags |= DIR_COLLECT_IGNORED;
|
||||||
setup_standard_excludes(dir);
|
setup_standard_excludes(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -405,7 +405,7 @@ static int merge_working_tree(struct checkout_opts *opts,
|
||||||
topts.verbose_update = !opts->quiet;
|
topts.verbose_update = !opts->quiet;
|
||||||
topts.fn = twoway_merge;
|
topts.fn = twoway_merge;
|
||||||
topts.dir = xcalloc(1, sizeof(*topts.dir));
|
topts.dir = xcalloc(1, sizeof(*topts.dir));
|
||||||
topts.dir->show_ignored = 1;
|
topts.dir->flags |= DIR_SHOW_IGNORED;
|
||||||
topts.dir->exclude_per_dir = ".gitignore";
|
topts.dir->exclude_per_dir = ".gitignore";
|
||||||
tree = parse_tree_indirect(old->commit->object.sha1);
|
tree = parse_tree_indirect(old->commit->object.sha1);
|
||||||
init_tree_desc(&trees[0], tree->buffer, tree->size);
|
init_tree_desc(&trees[0], tree->buffer, tree->size);
|
||||||
|
|
|
@ -60,7 +60,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
|
||||||
|
|
||||||
memset(&dir, 0, sizeof(dir));
|
memset(&dir, 0, sizeof(dir));
|
||||||
if (ignored_only)
|
if (ignored_only)
|
||||||
dir.show_ignored = 1;
|
dir.flags |= DIR_SHOW_IGNORED;
|
||||||
|
|
||||||
if (ignored && ignored_only)
|
if (ignored && ignored_only)
|
||||||
die("-x and -X cannot be used together");
|
die("-x and -X cannot be used together");
|
||||||
|
@ -69,7 +69,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
|
||||||
die("clean.requireForce%s set and -n or -f not given; "
|
die("clean.requireForce%s set and -n or -f not given; "
|
||||||
"refusing to clean", config_set ? "" : " not");
|
"refusing to clean", config_set ? "" : " not");
|
||||||
|
|
||||||
dir.show_other_directories = 1;
|
dir.flags |= DIR_SHOW_OTHER_DIRECTORIES;
|
||||||
|
|
||||||
if (!ignored)
|
if (!ignored)
|
||||||
setup_standard_excludes(&dir);
|
setup_standard_excludes(&dir);
|
||||||
|
|
|
@ -174,7 +174,8 @@ static void show_files(struct dir_struct *dir, const char *prefix)
|
||||||
for (i = 0; i < active_nr; i++) {
|
for (i = 0; i < active_nr; i++) {
|
||||||
struct cache_entry *ce = active_cache[i];
|
struct cache_entry *ce = active_cache[i];
|
||||||
int dtype = ce_to_dtype(ce);
|
int dtype = ce_to_dtype(ce);
|
||||||
if (excluded(dir, ce->name, &dtype) != dir->show_ignored)
|
if (excluded(dir, ce->name, &dtype) !=
|
||||||
|
!!(dir->flags & DIR_SHOW_IGNORED))
|
||||||
continue;
|
continue;
|
||||||
if (show_unmerged && !ce_stage(ce))
|
if (show_unmerged && !ce_stage(ce))
|
||||||
continue;
|
continue;
|
||||||
|
@ -189,7 +190,8 @@ static void show_files(struct dir_struct *dir, const char *prefix)
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int err;
|
int err;
|
||||||
int dtype = ce_to_dtype(ce);
|
int dtype = ce_to_dtype(ce);
|
||||||
if (excluded(dir, ce->name, &dtype) != dir->show_ignored)
|
if (excluded(dir, ce->name, &dtype) !=
|
||||||
|
!!(dir->flags & DIR_SHOW_IGNORED))
|
||||||
continue;
|
continue;
|
||||||
if (ce->ce_flags & CE_UPDATE)
|
if (ce->ce_flags & CE_UPDATE)
|
||||||
continue;
|
continue;
|
||||||
|
@ -432,7 +434,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp(arg, "-i") || !strcmp(arg, "--ignored")) {
|
if (!strcmp(arg, "-i") || !strcmp(arg, "--ignored")) {
|
||||||
dir.show_ignored = 1;
|
dir.flags |= DIR_SHOW_IGNORED;
|
||||||
require_work_tree = 1;
|
require_work_tree = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -446,11 +448,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp(arg, "--directory")) {
|
if (!strcmp(arg, "--directory")) {
|
||||||
dir.show_other_directories = 1;
|
dir.flags |= DIR_SHOW_OTHER_DIRECTORIES;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp(arg, "--no-empty-directory")) {
|
if (!strcmp(arg, "--no-empty-directory")) {
|
||||||
dir.hide_empty_directories = 1;
|
dir.flags |= DIR_HIDE_EMPTY_DIRECTORIES;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp(arg, "-u") || !strcmp(arg, "--unmerged")) {
|
if (!strcmp(arg, "-u") || !strcmp(arg, "--unmerged")) {
|
||||||
|
@ -542,7 +544,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
|
||||||
ps_matched = xcalloc(1, num);
|
ps_matched = xcalloc(1, num);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir.show_ignored && !exc_given) {
|
if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given) {
|
||||||
fprintf(stderr, "%s: --ignored needs some exclude pattern\n",
|
fprintf(stderr, "%s: --ignored needs some exclude pattern\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
|
@ -636,7 +636,7 @@ static int checkout_fast_forward(unsigned char *head, unsigned char *remote)
|
||||||
memset(&opts, 0, sizeof(opts));
|
memset(&opts, 0, sizeof(opts));
|
||||||
memset(&t, 0, sizeof(t));
|
memset(&t, 0, sizeof(t));
|
||||||
memset(&dir, 0, sizeof(dir));
|
memset(&dir, 0, sizeof(dir));
|
||||||
dir.show_ignored = 1;
|
dir.flags |= DIR_SHOW_IGNORED;
|
||||||
dir.exclude_per_dir = ".gitignore";
|
dir.exclude_per_dir = ".gitignore";
|
||||||
opts.dir = &dir;
|
opts.dir = &dir;
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
|
||||||
die("more than one --exclude-per-directory are given.");
|
die("more than one --exclude-per-directory are given.");
|
||||||
|
|
||||||
dir = xcalloc(1, sizeof(*opts.dir));
|
dir = xcalloc(1, sizeof(*opts.dir));
|
||||||
dir->show_ignored = 1;
|
dir->flags |= DIR_SHOW_IGNORED;
|
||||||
dir->exclude_per_dir = arg + 24;
|
dir->exclude_per_dir = arg + 24;
|
||||||
opts.dir = dir;
|
opts.dir = dir;
|
||||||
/* We do not need to nor want to do read-directory
|
/* We do not need to nor want to do read-directory
|
||||||
|
|
17
dir.c
17
dir.c
|
@ -487,14 +487,14 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
|
||||||
return recurse_into_directory;
|
return recurse_into_directory;
|
||||||
|
|
||||||
case index_gitdir:
|
case index_gitdir:
|
||||||
if (dir->show_other_directories)
|
if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
|
||||||
return ignore_directory;
|
return ignore_directory;
|
||||||
return show_directory;
|
return show_directory;
|
||||||
|
|
||||||
case index_nonexistent:
|
case index_nonexistent:
|
||||||
if (dir->show_other_directories)
|
if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
|
||||||
break;
|
break;
|
||||||
if (!dir->no_gitlinks) {
|
if (!(dir->flags & DIR_NO_GITLINKS)) {
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
if (resolve_gitlink_ref(dirname, "HEAD", sha1) == 0)
|
if (resolve_gitlink_ref(dirname, "HEAD", sha1) == 0)
|
||||||
return show_directory;
|
return show_directory;
|
||||||
|
@ -503,7 +503,7 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is the "show_other_directories" case */
|
/* This is the "show_other_directories" case */
|
||||||
if (!dir->hide_empty_directories)
|
if (!(dir->flags & DIR_HIDE_EMPTY_DIRECTORIES))
|
||||||
return show_directory;
|
return show_directory;
|
||||||
if (!read_directory_recursive(dir, dirname, dirname, len, 1, simplify))
|
if (!read_directory_recursive(dir, dirname, dirname, len, 1, simplify))
|
||||||
return ignore_directory;
|
return ignore_directory;
|
||||||
|
@ -601,7 +601,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
|
||||||
|
|
||||||
dtype = DTYPE(de);
|
dtype = DTYPE(de);
|
||||||
exclude = excluded(dir, fullname, &dtype);
|
exclude = excluded(dir, fullname, &dtype);
|
||||||
if (exclude && dir->collect_ignored
|
if (exclude && (dir->flags & DIR_COLLECT_IGNORED)
|
||||||
&& in_pathspec(fullname, baselen + len, simplify))
|
&& in_pathspec(fullname, baselen + len, simplify))
|
||||||
dir_add_ignored(dir, fullname, baselen + len);
|
dir_add_ignored(dir, fullname, baselen + len);
|
||||||
|
|
||||||
|
@ -609,7 +609,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
|
||||||
* Excluded? If we don't explicitly want to show
|
* Excluded? If we don't explicitly want to show
|
||||||
* ignored files, ignore it
|
* ignored files, ignore it
|
||||||
*/
|
*/
|
||||||
if (exclude && !dir->show_ignored)
|
if (exclude && !(dir->flags & DIR_SHOW_IGNORED))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (dtype == DT_UNKNOWN)
|
if (dtype == DT_UNKNOWN)
|
||||||
|
@ -621,7 +621,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
|
||||||
* even if we don't ignore them, since the
|
* even if we don't ignore them, since the
|
||||||
* directory may contain files that we do..
|
* directory may contain files that we do..
|
||||||
*/
|
*/
|
||||||
if (!exclude && dir->show_ignored) {
|
if (!exclude && (dir->flags & DIR_SHOW_IGNORED)) {
|
||||||
if (dtype != DT_DIR)
|
if (dtype != DT_DIR)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -634,7 +634,8 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
|
||||||
len++;
|
len++;
|
||||||
switch (treat_directory(dir, fullname, baselen + len, simplify)) {
|
switch (treat_directory(dir, fullname, baselen + len, simplify)) {
|
||||||
case show_directory:
|
case show_directory:
|
||||||
if (exclude != dir->show_ignored)
|
if (exclude != !!(dir->flags
|
||||||
|
& DIR_SHOW_IGNORED))
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
case recurse_into_directory:
|
case recurse_into_directory:
|
||||||
|
|
12
dir.h
12
dir.h
|
@ -34,11 +34,13 @@ struct exclude_stack {
|
||||||
struct dir_struct {
|
struct dir_struct {
|
||||||
int nr, alloc;
|
int nr, alloc;
|
||||||
int ignored_nr, ignored_alloc;
|
int ignored_nr, ignored_alloc;
|
||||||
unsigned int show_ignored:1,
|
enum {
|
||||||
show_other_directories:1,
|
DIR_SHOW_IGNORED = 1<<0,
|
||||||
hide_empty_directories:1,
|
DIR_SHOW_OTHER_DIRECTORIES = 1<<1,
|
||||||
no_gitlinks:1,
|
DIR_HIDE_EMPTY_DIRECTORIES = 1<<2,
|
||||||
collect_ignored:1;
|
DIR_NO_GITLINKS = 1<<3,
|
||||||
|
DIR_COLLECT_IGNORED = 1<<4
|
||||||
|
} flags;
|
||||||
struct dir_entry **entries;
|
struct dir_entry **entries;
|
||||||
struct dir_entry **ignored;
|
struct dir_entry **ignored;
|
||||||
|
|
||||||
|
|
|
@ -250,10 +250,9 @@ static void wt_status_print_untracked(struct wt_status *s)
|
||||||
|
|
||||||
memset(&dir, 0, sizeof(dir));
|
memset(&dir, 0, sizeof(dir));
|
||||||
|
|
||||||
if (!s->untracked) {
|
if (!s->untracked)
|
||||||
dir.show_other_directories = 1;
|
dir.flags |=
|
||||||
dir.hide_empty_directories = 1;
|
DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
|
||||||
}
|
|
||||||
setup_standard_excludes(&dir);
|
setup_standard_excludes(&dir);
|
||||||
|
|
||||||
read_directory(&dir, ".", "", 0, NULL);
|
read_directory(&dir, ".", "", 0, NULL);
|
||||||
|
|
Loading…
Reference in a new issue