dir: convert is_excluded to take an index

Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed May 5, 2017 at 12:53 UTC a0bba65b107651946431bee4c71d05d812988d9d
7 files changed +19 -13
builtin/add.c
+1 -1
@@ -436,7 +436,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
436 !file_exists(path))) {
437 if (ignore_missing) {
438 int dtype = DT_UNKNOWN;
439 - if (is_excluded(&dir, path, &dtype))
439 + if (is_excluded(&dir, &the_index, path, &dtype))
440 dir_add_ignored(&dir, &the_index,
441 path, pathspec.items[i].len);
442 } else
builtin/check-ignore.c
+2 -1
@@ -101,7 +101,8 @@ static int check_ignore(struct dir_struct *dir,
101 full_path = pathspec.items[i].match;
102 exclude = NULL;
103 if (!seen[i]) {
104 - exclude = last_exclude_matching(dir, full_path, &dtype);
104 + exclude = last_exclude_matching(dir, &the_index,
105 + full_path, &dtype);
106 }
107 if (!quiet && (exclude || show_non_matching))
108 output_exclude(pathspec.items[i].original, exclude);
builtin/clean.c
+1 -1
@@ -683,7 +683,7 @@ static int filter_by_patterns_cmd(void)
683 for_each_string_list_item(item, &del_list) {
684 int dtype = DT_UNKNOWN;
685
686 - if (is_excluded(&dir, item->string, &dtype)) {
686 + if (is_excluded(&dir, &the_index, item->string, &dtype)) {
687 *item->string = '\0';
688 changed++;
689 }
builtin/ls-files.c
+1 -1
@@ -322,7 +322,7 @@ static void show_ru_info(void)
322 static int ce_excluded(struct dir_struct *dir, const struct cache_entry *ce)
323 {
324 int dtype = ce_to_dtype(ce);
325 - return is_excluded(dir, ce->name, &dtype);
325 + return is_excluded(dir, &the_index, ce->name, &dtype);
326 }
327
328 static void show_files(struct dir_struct *dir)
dir.c
+9 -7
@@ -1204,19 +1204,20 @@ static void prep_exclude(struct dir_struct *dir,
1204 * undecided.
1205 */
1206 struct exclude *last_exclude_matching(struct dir_struct *dir,
1207 - const char *pathname,
1208 - int *dtype_p)
1207 + struct index_state *istate,
1208 + const char *pathname,
1209 + int *dtype_p)
1210 {
1211 int pathlen = strlen(pathname);
1212 const char *basename = strrchr(pathname, '/');
1213 basename = (basename) ? basename+1 : pathname;
1214
1214 - prep_exclude(dir, &the_index, pathname, basename-pathname);
1215 + prep_exclude(dir, istate, pathname, basename-pathname);
1216
1217 if (dir->exclude)
1218 return dir->exclude;
1219
1219 - return last_exclude_matching_from_lists(dir, &the_index, pathname, pathlen,
1220 + return last_exclude_matching_from_lists(dir, istate, pathname, pathlen,
1221 basename, dtype_p);
1222 }
1223
@@ -1225,10 +1226,11 @@ struct exclude *last_exclude_matching(struct dir_struct *dir,
1226 * scans all exclude lists to determine whether pathname is excluded.
1227 * Returns 1 if true, otherwise 0.
1228 */
1228 -int is_excluded(struct dir_struct *dir, const char *pathname, int *dtype_p)
1229 +int is_excluded(struct dir_struct *dir, struct index_state *istate,
1230 + const char *pathname, int *dtype_p)
1231 {
1232 struct exclude *exclude =
1231 - last_exclude_matching(dir, pathname, dtype_p);
1233 + last_exclude_matching(dir, istate, pathname, dtype_p);
1234 if (exclude)
1235 return exclude->flags & EXC_FLAG_NEGATIVE ? 0 : 1;
1236 return 0;
@@ -1573,7 +1575,7 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
1575 (directory_exists_in_index(&the_index, path->buf, path->len) == index_nonexistent))
1576 return path_none;
1577
1576 - exclude = is_excluded(dir, path->buf, &dtype);
1578 + exclude = is_excluded(dir, &the_index, path->buf, &dtype);
1579
1580 /*
1581 * Excluded? If we don't explicitly want to show
dir.h
+4 -1
@@ -236,9 +236,12 @@ extern int match_pathname(const char *, int,
236 const char *, int, int, unsigned);
237
238 extern struct exclude *last_exclude_matching(struct dir_struct *dir,
239 + struct index_state *istate,
240 const char *name, int *dtype);
241
241 -extern int is_excluded(struct dir_struct *dir, const char *name, int *dtype);
242 +extern int is_excluded(struct dir_struct *dir,
243 + struct index_state *istate,
244 + const char *name, int *dtype);
245
246 extern struct exclude_list *add_exclude_list(struct dir_struct *dir,
247 int group_type, const char *src);
unpack-trees.c
+1 -1
@@ -1634,7 +1634,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
1634 return 0;
1635
1636 if (o->dir &&
1637 - is_excluded(o->dir, name, &dtype))
1637 + is_excluded(o->dir, &the_index, name, &dtype))
1638 /*
1639 * ce->name is explicitly excluded, so it is Ok to
1640 * overwrite it.