Skip to content

Commit 7c4c97c

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 81d3fe9 commit 7c4c97c

File tree

9 files changed

+33
-29
lines changed

9 files changed

+33
-29
lines changed

builtin-add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
104104
/* Set up the default git porcelain excludes */
105105
memset(dir, 0, sizeof(*dir));
106106
if (!ignored_too) {
107-
dir->collect_ignored = 1;
107+
dir->flags |= DIR_COLLECT_IGNORED;
108108
setup_standard_excludes(dir);
109109
}
110110

builtin-checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static int merge_working_tree(struct checkout_opts *opts,
405405
topts.verbose_update = !opts->quiet;
406406
topts.fn = twoway_merge;
407407
topts.dir = xcalloc(1, sizeof(*topts.dir));
408-
topts.dir->show_ignored = 1;
408+
topts.dir->flags |= DIR_SHOW_IGNORED;
409409
topts.dir->exclude_per_dir = ".gitignore";
410410
tree = parse_tree_indirect(old->commit->object.sha1);
411411
init_tree_desc(&trees[0], tree->buffer, tree->size);

builtin-clean.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
6060

6161
memset(&dir, 0, sizeof(dir));
6262
if (ignored_only)
63-
dir.show_ignored = 1;
63+
dir.flags |= DIR_SHOW_IGNORED;
6464

6565
if (ignored && ignored_only)
6666
die("-x and -X cannot be used together");
@@ -69,7 +69,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
6969
die("clean.requireForce%s set and -n or -f not given; "
7070
"refusing to clean", config_set ? "" : " not");
7171

72-
dir.show_other_directories = 1;
72+
dir.flags |= DIR_SHOW_OTHER_DIRECTORIES;
7373

7474
if (!ignored)
7575
setup_standard_excludes(&dir);

builtin-ls-files.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ static void show_files(struct dir_struct *dir, const char *prefix)
174174
for (i = 0; i < active_nr; i++) {
175175
struct cache_entry *ce = active_cache[i];
176176
int dtype = ce_to_dtype(ce);
177-
if (excluded(dir, ce->name, &dtype) != dir->show_ignored)
177+
if (excluded(dir, ce->name, &dtype) !=
178+
!!(dir->flags & DIR_SHOW_IGNORED))
178179
continue;
179180
if (show_unmerged && !ce_stage(ce))
180181
continue;
@@ -189,7 +190,8 @@ static void show_files(struct dir_struct *dir, const char *prefix)
189190
struct stat st;
190191
int err;
191192
int dtype = ce_to_dtype(ce);
192-
if (excluded(dir, ce->name, &dtype) != dir->show_ignored)
193+
if (excluded(dir, ce->name, &dtype) !=
194+
!!(dir->flags & DIR_SHOW_IGNORED))
193195
continue;
194196
if (ce->ce_flags & CE_UPDATE)
195197
continue;
@@ -432,7 +434,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
432434
continue;
433435
}
434436
if (!strcmp(arg, "-i") || !strcmp(arg, "--ignored")) {
435-
dir.show_ignored = 1;
437+
dir.flags |= DIR_SHOW_IGNORED;
436438
require_work_tree = 1;
437439
continue;
438440
}
@@ -446,11 +448,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
446448
continue;
447449
}
448450
if (!strcmp(arg, "--directory")) {
449-
dir.show_other_directories = 1;
451+
dir.flags |= DIR_SHOW_OTHER_DIRECTORIES;
450452
continue;
451453
}
452454
if (!strcmp(arg, "--no-empty-directory")) {
453-
dir.hide_empty_directories = 1;
455+
dir.flags |= DIR_HIDE_EMPTY_DIRECTORIES;
454456
continue;
455457
}
456458
if (!strcmp(arg, "-u") || !strcmp(arg, "--unmerged")) {
@@ -542,7 +544,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
542544
ps_matched = xcalloc(1, num);
543545
}
544546

545-
if (dir.show_ignored && !exc_given) {
547+
if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given) {
546548
fprintf(stderr, "%s: --ignored needs some exclude pattern\n",
547549
argv[0]);
548550
exit(1);

builtin-merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ static int checkout_fast_forward(unsigned char *head, unsigned char *remote)
636636
memset(&opts, 0, sizeof(opts));
637637
memset(&t, 0, sizeof(t));
638638
memset(&dir, 0, sizeof(dir));
639-
dir.show_ignored = 1;
639+
dir.flags |= DIR_SHOW_IGNORED;
640640
dir.exclude_per_dir = ".gitignore";
641641
opts.dir = &dir;
642642

builtin-read-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
170170
die("more than one --exclude-per-directory are given.");
171171

172172
dir = xcalloc(1, sizeof(*opts.dir));
173-
dir->show_ignored = 1;
173+
dir->flags |= DIR_SHOW_IGNORED;
174174
dir->exclude_per_dir = arg + 24;
175175
opts.dir = dir;
176176
/* We do not need to nor want to do read-directory

dir.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,14 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
487487
return recurse_into_directory;
488488

489489
case index_gitdir:
490-
if (dir->show_other_directories)
490+
if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
491491
return ignore_directory;
492492
return show_directory;
493493

494494
case index_nonexistent:
495-
if (dir->show_other_directories)
495+
if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
496496
break;
497-
if (!dir->no_gitlinks) {
497+
if (!(dir->flags & DIR_NO_GITLINKS)) {
498498
unsigned char sha1[20];
499499
if (resolve_gitlink_ref(dirname, "HEAD", sha1) == 0)
500500
return show_directory;
@@ -503,7 +503,7 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
503503
}
504504

505505
/* This is the "show_other_directories" case */
506-
if (!dir->hide_empty_directories)
506+
if (!(dir->flags & DIR_HIDE_EMPTY_DIRECTORIES))
507507
return show_directory;
508508
if (!read_directory_recursive(dir, dirname, dirname, len, 1, simplify))
509509
return ignore_directory;
@@ -601,15 +601,15 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
601601

602602
dtype = DTYPE(de);
603603
exclude = excluded(dir, fullname, &dtype);
604-
if (exclude && dir->collect_ignored
604+
if (exclude && (dir->flags & DIR_COLLECT_IGNORED)
605605
&& in_pathspec(fullname, baselen + len, simplify))
606606
dir_add_ignored(dir, fullname, baselen + len);
607607

608608
/*
609609
* Excluded? If we don't explicitly want to show
610610
* ignored files, ignore it
611611
*/
612-
if (exclude && !dir->show_ignored)
612+
if (exclude && !(dir->flags & DIR_SHOW_IGNORED))
613613
continue;
614614

615615
if (dtype == DT_UNKNOWN)
@@ -621,7 +621,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
621621
* even if we don't ignore them, since the
622622
* directory may contain files that we do..
623623
*/
624-
if (!exclude && dir->show_ignored) {
624+
if (!exclude && (dir->flags & DIR_SHOW_IGNORED)) {
625625
if (dtype != DT_DIR)
626626
continue;
627627
}
@@ -634,7 +634,8 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
634634
len++;
635635
switch (treat_directory(dir, fullname, baselen + len, simplify)) {
636636
case show_directory:
637-
if (exclude != dir->show_ignored)
637+
if (exclude != !!(dir->flags
638+
& DIR_SHOW_IGNORED))
638639
continue;
639640
break;
640641
case recurse_into_directory:

dir.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ struct exclude_stack {
3434
struct dir_struct {
3535
int nr, alloc;
3636
int ignored_nr, ignored_alloc;
37-
unsigned int show_ignored:1,
38-
show_other_directories:1,
39-
hide_empty_directories:1,
40-
no_gitlinks:1,
41-
collect_ignored:1;
37+
enum {
38+
DIR_SHOW_IGNORED = 1<<0,
39+
DIR_SHOW_OTHER_DIRECTORIES = 1<<1,
40+
DIR_HIDE_EMPTY_DIRECTORIES = 1<<2,
41+
DIR_NO_GITLINKS = 1<<3,
42+
DIR_COLLECT_IGNORED = 1<<4
43+
} flags;
4244
struct dir_entry **entries;
4345
struct dir_entry **ignored;
4446

wt-status.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,9 @@ static void wt_status_print_untracked(struct wt_status *s)
250250

251251
memset(&dir, 0, sizeof(dir));
252252

253-
if (!s->untracked) {
254-
dir.show_other_directories = 1;
255-
dir.hide_empty_directories = 1;
256-
}
253+
if (!s->untracked)
254+
dir.flags |=
255+
DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
257256
setup_standard_excludes(&dir);
258257

259258
read_directory(&dir, ".", "", 0, NULL);

0 commit comments

Comments
 (0)