dir.c: replace is_path_excluded with now equivalent is_excluded API

Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karsten Blees committed Apr 15, 2013 at 21:12 UTC b07bc8c8c3c492d657a8bedf04ff939763ea8222
7 files changed +16 -116
builtin/add.c
+1 -4
@@ -444,9 +444,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
444
445 if (pathspec) {
446 int i;
447 - struct path_exclude_check check;
447
449 - path_exclude_check_init(&check, &dir);
448 if (!seen)
449 seen = find_pathspecs_matching_against_index(pathspec);
450 for (i = 0; pathspec[i]; i++) {
@@ -454,7 +452,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
452 && !file_exists(pathspec[i])) {
453 if (ignore_missing) {
454 int dtype = DT_UNKNOWN;
457 - if (is_path_excluded(&check, pathspec[i], -1, &dtype))
455 + if (is_excluded(&dir, pathspec[i], &dtype))
456 dir_add_ignored(&dir, pathspec[i], strlen(pathspec[i]));
457 } else
458 die(_("pathspec '%s' did not match any files"),
@@ -462,7 +460,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
460 }
461 }
462 free(seen);
465 - path_exclude_check_clear(&check);
463 }
464
465 plug_bulk_checkin();
builtin/check-ignore.c
+1 -5
@@ -59,7 +59,6 @@ static int check_ignore(const char *prefix, const char **pathspec)
59 const char *path, *full_path;
60 char *seen;
61 int num_ignored = 0, dtype = DT_UNKNOWN, i;
62 - struct path_exclude_check check;
62 struct exclude *exclude;
63
64 /* read_cache() is only necessary so we can watch out for submodules. */
@@ -76,7 +75,6 @@ static int check_ignore(const char *prefix, const char **pathspec)
75 return 0;
76 }
77
79 - path_exclude_check_init(&check, &dir);
78 /*
79 * look for pathspecs matching entries in the index, since these
80 * should not be ignored, in order to be consistent with
@@ -90,8 +88,7 @@ static int check_ignore(const char *prefix, const char **pathspec)
88 full_path = check_path_for_gitlink(full_path);
89 die_if_path_beyond_symlink(full_path, prefix);
90 if (!seen[i]) {
93 - exclude = last_exclude_matching_path(&check, full_path,
94 - -1, &dtype);
91 + exclude = last_exclude_matching(&dir, full_path, &dtype);
92 if (exclude) {
93 if (!quiet)
94 output_exclude(path, exclude);
@@ -101,7 +98,6 @@ static int check_ignore(const char *prefix, const char **pathspec)
98 }
99 free(seen);
100 clear_directory(&dir);
104 - path_exclude_check_clear(&check);
101
102 return num_ignored;
103 }
builtin/ls-files.c
+4 -11
@@ -201,19 +201,15 @@ static void show_ru_info(void)
201 }
202 }
203
204 -static int ce_excluded(struct path_exclude_check *check, struct cache_entry *ce)
204 +static int ce_excluded(struct dir_struct *dir, struct cache_entry *ce)
205 {
206 int dtype = ce_to_dtype(ce);
207 - return is_path_excluded(check, ce->name, ce_namelen(ce), &dtype);
207 + return is_excluded(dir, ce->name, &dtype);
208 }
209
210 static void show_files(struct dir_struct *dir)
211 {
212 int i;
213 - struct path_exclude_check check;
214 -
215 - if ((dir->flags & DIR_SHOW_IGNORED))
216 - path_exclude_check_init(&check, dir);
213
214 /* For cached/deleted files we don't need to even do the readdir */
215 if (show_others || show_killed) {
@@ -227,7 +223,7 @@ static void show_files(struct dir_struct *dir)
223 for (i = 0; i < active_nr; i++) {
224 struct cache_entry *ce = active_cache[i];
225 if ((dir->flags & DIR_SHOW_IGNORED) &&
230 - !ce_excluded(&check, ce))
226 + !ce_excluded(dir, ce))
227 continue;
228 if (show_unmerged && !ce_stage(ce))
229 continue;
@@ -243,7 +239,7 @@ static void show_files(struct dir_struct *dir)
239 struct stat st;
240 int err;
241 if ((dir->flags & DIR_SHOW_IGNORED) &&
246 - !ce_excluded(&check, ce))
242 + !ce_excluded(dir, ce))
243 continue;
244 if (ce->ce_flags & CE_UPDATE)
245 continue;
@@ -256,9 +252,6 @@ static void show_files(struct dir_struct *dir)
252 show_ce_entry(tag_modified, ce);
253 }
254 }
259 -
260 - if ((dir->flags & DIR_SHOW_IGNORED))
261 - path_exclude_check_clear(&check);
255 }
256
257 /*
dir.c
+6 -73
@@ -843,7 +843,7 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
843 * Returns the exclude_list element which matched, or NULL for
844 * undecided.
845 */
846 -static struct exclude *last_exclude_matching(struct dir_struct *dir,
846 +struct exclude *last_exclude_matching(struct dir_struct *dir,
847 const char *pathname,
848 int *dtype_p)
849 {
@@ -865,7 +865,7 @@ static struct exclude *last_exclude_matching(struct dir_struct *dir,
865 * scans all exclude lists to determine whether pathname is excluded.
866 * Returns 1 if true, otherwise 0.
867 */
868 -static int is_excluded(struct dir_struct *dir, const char *pathname, int *dtype_p)
868 +int is_excluded(struct dir_struct *dir, const char *pathname, int *dtype_p)
869 {
870 struct exclude *exclude =
871 last_exclude_matching(dir, pathname, dtype_p);
@@ -874,47 +874,6 @@ static int is_excluded(struct dir_struct *dir, const char *pathname, int *dtype_
874 return 0;
875 }
876
877 -void path_exclude_check_init(struct path_exclude_check *check,
878 - struct dir_struct *dir)
879 -{
880 - check->dir = dir;
881 -}
882 -
883 -void path_exclude_check_clear(struct path_exclude_check *check)
884 -{
885 -}
886 -
887 -/*
888 - * For each subdirectory in name, starting with the top-most, checks
889 - * to see if that subdirectory is excluded, and if so, returns the
890 - * corresponding exclude structure. Otherwise, checks whether name
891 - * itself (which is presumably a file) is excluded.
892 - *
893 - * A path to a directory known to be excluded is left in check->path to
894 - * optimize for repeated checks for files in the same excluded directory.
895 - */
896 -struct exclude *last_exclude_matching_path(struct path_exclude_check *check,
897 - const char *name, int namelen,
898 - int *dtype)
899 -{
900 - return last_exclude_matching(check->dir, name, dtype);
901 -}
902 -
903 -/*
904 - * Is this name excluded? This is for a caller like show_files() that
905 - * do not honor directory hierarchy and iterate through paths that are
906 - * possibly in an ignored directory.
907 - */
908 -int is_path_excluded(struct path_exclude_check *check,
909 - const char *name, int namelen, int *dtype)
910 -{
911 - struct exclude *exclude =
912 - last_exclude_matching_path(check, name, namelen, dtype);
913 - if (exclude)
914 - return exclude->flags & EXC_FLAG_NEGATIVE ? 0 : 1;
915 - return 0;
916 -}
917 -
877 static struct dir_entry *dir_entry_new(const char *pathname, int len)
878 {
879 struct dir_entry *ent;
@@ -1086,15 +1045,6 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
1045
1046 /* This is the "show_other_directories" case */
1047
1089 - /* might be a sub directory in an excluded directory */
1090 - if (!exclude) {
1091 - struct path_exclude_check check;
1092 - int dt = DT_DIR;
1093 - path_exclude_check_init(&check, dir);
1094 - exclude = is_path_excluded(&check, dirname, len, &dt);
1095 - path_exclude_check_clear(&check);
1096 - }
1097 -
1048 /*
1049 * We are looking for ignored files and our directory is not ignored,
1050 * check if it contains untracked files (i.e. is listed as untracked)
@@ -1129,27 +1079,13 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
1079 *
1080 * Return 1 for exclude, 0 for include.
1081 */
1132 -static int treat_file(struct dir_struct *dir, struct strbuf *path, int exclude, int *dtype)
1082 +static int treat_file(struct dir_struct *dir, struct strbuf *path, int exclude)
1083 {
1134 - struct path_exclude_check check;
1135 - int exclude_file = 0;
1136 -
1084 /* Always exclude indexed files */
1085 if (index_name_exists(&the_index, path->buf, path->len, ignore_case))
1086 return 1;
1087
1141 - if (exclude)
1142 - exclude_file = !(dir->flags & DIR_SHOW_IGNORED);
1143 - else if (dir->flags & DIR_SHOW_IGNORED) {
1144 - path_exclude_check_init(&check, dir);
1145 -
1146 - if (!is_path_excluded(&check, path->buf, path->len, dtype))
1147 - exclude_file = 1;
1148 -
1149 - path_exclude_check_clear(&check);
1150 - }
1151 -
1152 - return exclude_file;
1088 + return exclude == !(dir->flags & DIR_SHOW_IGNORED);
1089 }
1090
1091 /*
@@ -1306,12 +1242,9 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
1242 break;
1243 case DT_REG:
1244 case DT_LNK:
1309 - switch (treat_file(dir, path, exclude, &dtype)) {
1310 - case 1:
1245 + if (treat_file(dir, path, exclude))
1246 return path_ignored;
1312 - default:
1313 - break;
1314 - }
1247 + break;
1248 }
1249 return path_handled;
1250 }
dir.h
+3 -13
@@ -151,20 +151,10 @@ extern int match_pathname(const char *, int,
151 const char *, int,
152 const char *, int, int, int);
153
154 -/*
155 - * The is_excluded() API is meant for callers that check each level of leading
156 - * directory hierarchies with is_excluded() to avoid recursing into excluded
157 - * directories. Callers that do not do so should use this API instead.
158 - */
159 -struct path_exclude_check {
160 - struct dir_struct *dir;
161 -};
162 -extern void path_exclude_check_init(struct path_exclude_check *, struct dir_struct *);
163 -extern void path_exclude_check_clear(struct path_exclude_check *);
164 -extern struct exclude *last_exclude_matching_path(struct path_exclude_check *, const char *,
165 - int namelen, int *dtype);
166 -extern int is_path_excluded(struct path_exclude_check *, const char *, int namelen, int *dtype);
154 +extern struct exclude *last_exclude_matching(struct dir_struct *dir,
155 + const char *name, int *dtype);
156
157 +extern int is_excluded(struct dir_struct *dir, const char *name, int *dtype);
158
159 extern struct exclude_list *add_exclude_list(struct dir_struct *dir,
160 int group_type, const char *src);
unpack-trees.c
+1 -9
@@ -1026,10 +1026,6 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1026 o->el = &el;
1027 }
1028
1029 - if (o->dir) {
1030 - o->path_exclude_check = xmalloc(sizeof(struct path_exclude_check));
1031 - path_exclude_check_init(o->path_exclude_check, o->dir);
1032 - }
1029 memset(&o->result, 0, sizeof(o->result));
1030 o->result.initialized = 1;
1031 o->result.timestamp.sec = o->src_index->timestamp.sec;
@@ -1155,10 +1151,6 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1151
1152 done:
1153 clear_exclude_list(&el);
1158 - if (o->path_exclude_check) {
1159 - path_exclude_check_clear(o->path_exclude_check);
1160 - free(o->path_exclude_check);
1161 - }
1154 return ret;
1155
1156 return_failed:
@@ -1375,7 +1367,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
1367 return 0;
1368
1369 if (o->dir &&
1378 - is_path_excluded(o->path_exclude_check, name, -1, &dtype))
1370 + is_excluded(o->dir, name, &dtype))
1371 /*
1372 * ce->name is explicitly excluded, so it is Ok to
1373 * overwrite it.
unpack-trees.h
-1
@@ -52,7 +52,6 @@ struct unpack_trees_options {
52 const char *prefix;
53 int cache_bottom;
54 struct dir_struct *dir;
55 - struct path_exclude_check *path_exclude_check;
55 struct pathspec *pathspec;
56 merge_fn_t fn;
57 const char *msgs[NB_UNPACK_TREES_ERROR_TYPES];