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>
Johannes Schindelin committed
Feb 16, 2009 at 13:20 UTC
7c4c97c0ac0cd66861d0c2b8bd7a47ed3c523ea7
9 files changed
+33
-29
builtin-add.c
+1
-1
@@ -104,7 +104,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
104
/* Set up the default git porcelain excludes */
105
memset(dir, 0, sizeof(*dir));
106
if (!ignored_too) {
107
- dir->collect_ignored = 1;
107
+ dir->flags |= DIR_COLLECT_IGNORED;
108
setup_standard_excludes(dir);
109
}
110
builtin-checkout.c
+1
-1
@@ -405,7 +405,7 @@ static int merge_working_tree(struct checkout_opts *opts,
405
topts.verbose_update = !opts->quiet;
406
topts.fn = twoway_merge;
407
topts.dir = xcalloc(1, sizeof(*topts.dir));
408
- topts.dir->show_ignored = 1;
408
+ topts.dir->flags |= DIR_SHOW_IGNORED;
409
topts.dir->exclude_per_dir = ".gitignore";
410
tree = parse_tree_indirect(old->commit->object.sha1);
411
init_tree_desc(&trees[0], tree->buffer, tree->size);
builtin-clean.c
+2
-2
@@ -60,7 +60,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
60
61
memset(&dir, 0, sizeof(dir));
62
if (ignored_only)
63
- dir.show_ignored = 1;
63
+ dir.flags |= DIR_SHOW_IGNORED;
64
65
if (ignored && ignored_only)
66
die("-x and -X cannot be used together");
@@ -69,7 +69,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
69
die("clean.requireForce%s set and -n or -f not given; "
70
"refusing to clean", config_set ? "" : " not");
71
72
- dir.show_other_directories = 1;
72
+ dir.flags |= DIR_SHOW_OTHER_DIRECTORIES;
73
74
if (!ignored)
75
setup_standard_excludes(&dir);
builtin-ls-files.c
+8
-6
@@ -174,7 +174,8 @@ static void show_files(struct dir_struct *dir, const char *prefix)
174
for (i = 0; i < active_nr; i++) {
175
struct cache_entry *ce = active_cache[i];
176
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))
179
continue;
180
if (show_unmerged && !ce_stage(ce))
181
continue;
@@ -189,7 +190,8 @@ static void show_files(struct dir_struct *dir, const char *prefix)
190
struct stat st;
191
int err;
192
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))
195
continue;
196
if (ce->ce_flags & CE_UPDATE)
197
continue;
@@ -432,7 +434,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
434
continue;
435
}
436
if (!strcmp(arg, "-i") || !strcmp(arg, "--ignored")) {
435
- dir.show_ignored = 1;
437
+ dir.flags |= DIR_SHOW_IGNORED;
438
require_work_tree = 1;
439
continue;
440
}
@@ -446,11 +448,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
448
continue;
449
}
450
if (!strcmp(arg, "--directory")) {
449
- dir.show_other_directories = 1;
451
+ dir.flags |= DIR_SHOW_OTHER_DIRECTORIES;
452
continue;
453
}
454
if (!strcmp(arg, "--no-empty-directory")) {
453
- dir.hide_empty_directories = 1;
455
+ dir.flags |= DIR_HIDE_EMPTY_DIRECTORIES;
456
continue;
457
}
458
if (!strcmp(arg, "-u") || !strcmp(arg, "--unmerged")) {
@@ -542,7 +544,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
544
ps_matched = xcalloc(1, num);
545
}
546
545
- if (dir.show_ignored && !exc_given) {
547
+ if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given) {
548
fprintf(stderr, "%s: --ignored needs some exclude pattern\n",
549
argv[0]);
550
exit(1);
builtin-merge.c
+1
-1
@@ -636,7 +636,7 @@ static int checkout_fast_forward(unsigned char *head, unsigned char *remote)
636
memset(&opts, 0, sizeof(opts));
637
memset(&t, 0, sizeof(t));
638
memset(&dir, 0, sizeof(dir));
639
- dir.show_ignored = 1;
639
+ dir.flags |= DIR_SHOW_IGNORED;
640
dir.exclude_per_dir = ".gitignore";
641
opts.dir = &dir;
642
builtin-read-tree.c
+1
-1
@@ -170,7 +170,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
170
die("more than one --exclude-per-directory are given.");
171
172
dir = xcalloc(1, sizeof(*opts.dir));
173
- dir->show_ignored = 1;
173
+ dir->flags |= DIR_SHOW_IGNORED;
174
dir->exclude_per_dir = arg + 24;
175
opts.dir = dir;
176
/* We do not need to nor want to do read-directory
dir.c
+9
-8
@@ -487,14 +487,14 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
487
return recurse_into_directory;
488
489
case index_gitdir:
490
- if (dir->show_other_directories)
490
+ if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
491
return ignore_directory;
492
return show_directory;
493
494
case index_nonexistent:
495
- if (dir->show_other_directories)
495
+ if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
496
break;
497
- if (!dir->no_gitlinks) {
497
+ if (!(dir->flags & DIR_NO_GITLINKS)) {
498
unsigned char sha1[20];
499
if (resolve_gitlink_ref(dirname, "HEAD", sha1) == 0)
500
return show_directory;
@@ -503,7 +503,7 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
503
}
504
505
/* This is the "show_other_directories" case */
506
- if (!dir->hide_empty_directories)
506
+ if (!(dir->flags & DIR_HIDE_EMPTY_DIRECTORIES))
507
return show_directory;
508
if (!read_directory_recursive(dir, dirname, dirname, len, 1, simplify))
509
return ignore_directory;
@@ -601,7 +601,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
601
602
dtype = DTYPE(de);
603
exclude = excluded(dir, fullname, &dtype);
604
- if (exclude && dir->collect_ignored
604
+ if (exclude && (dir->flags & DIR_COLLECT_IGNORED)
605
&& in_pathspec(fullname, baselen + len, simplify))
606
dir_add_ignored(dir, fullname, baselen + len);
607
@@ -609,7 +609,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
609
* Excluded? If we don't explicitly want to show
610
* ignored files, ignore it
611
*/
612
- if (exclude && !dir->show_ignored)
612
+ if (exclude && !(dir->flags & DIR_SHOW_IGNORED))
613
continue;
614
615
if (dtype == DT_UNKNOWN)
@@ -621,7 +621,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
621
* even if we don't ignore them, since the
622
* directory may contain files that we do..
623
*/
624
- if (!exclude && dir->show_ignored) {
624
+ if (!exclude && (dir->flags & DIR_SHOW_IGNORED)) {
625
if (dtype != DT_DIR)
626
continue;
627
}
@@ -634,7 +634,8 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
634
len++;
635
switch (treat_directory(dir, fullname, baselen + len, simplify)) {
636
case show_directory:
637
- if (exclude != dir->show_ignored)
637
+ if (exclude != !!(dir->flags
638
+ & DIR_SHOW_IGNORED))
639
continue;
640
break;
641
case recurse_into_directory:
dir.h
+7
-5
@@ -34,11 +34,13 @@ struct exclude_stack {
34
struct dir_struct {
35
int nr, alloc;
36
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;
44
struct dir_entry **entries;
45
struct dir_entry **ignored;
46
wt-status.c
+3
-4
@@ -250,10 +250,9 @@ static void wt_status_print_untracked(struct wt_status *s)
250
251
memset(&dir, 0, sizeof(dir));
252
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;
256
setup_standard_excludes(&dir);
257
258
read_directory(&dir, ".", "", 0, NULL);