dir: convert dir_add* 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 9e58becab9d2512bad0fdf150fedbea84d6b9b03
3 files changed +16 -9
builtin/add.c
+2 -1
@@ -437,7 +437,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
437 if (ignore_missing) {
438 int dtype = DT_UNKNOWN;
439 if (is_excluded(&dir, path, &dtype))
440 - dir_add_ignored(&dir, path, pathspec.items[i].len);
440 + dir_add_ignored(&dir, &the_index,
441 + path, pathspec.items[i].len);
442 } else
443 die(_("pathspec '%s' did not match any files"),
444 pathspec.items[i].original);
dir.c
+11 -7
@@ -1236,18 +1236,22 @@ static struct dir_entry *dir_entry_new(const char *pathname, int len)
1236 return ent;
1237 }
1238
1239 -static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len)
1239 +static struct dir_entry *dir_add_name(struct dir_struct *dir,
1240 + struct index_state *istate,
1241 + const char *pathname, int len)
1242 {
1241 - if (index_file_exists(&the_index, pathname, len, ignore_case))
1243 + if (index_file_exists(istate, pathname, len, ignore_case))
1244 return NULL;
1245
1246 ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc);
1247 return dir->entries[dir->nr++] = dir_entry_new(pathname, len);
1248 }
1249
1248 -struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len)
1250 +struct dir_entry *dir_add_ignored(struct dir_struct *dir,
1251 + struct index_state *istate,
1252 + const char *pathname, int len)
1253 {
1250 - if (!index_name_is_other(&the_index, pathname, len))
1254 + if (!index_name_is_other(istate, pathname, len))
1255 return NULL;
1256
1257 ALLOC_GROW(dir->ignored, dir->ignored_nr+1, dir->ignored_alloc);
@@ -1819,18 +1823,18 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
1823 switch (state) {
1824 case path_excluded:
1825 if (dir->flags & DIR_SHOW_IGNORED)
1822 - dir_add_name(dir, path.buf, path.len);
1826 + dir_add_name(dir, &the_index, path.buf, path.len);
1827 else if ((dir->flags & DIR_SHOW_IGNORED_TOO) ||
1828 ((dir->flags & DIR_COLLECT_IGNORED) &&
1829 exclude_matches_pathspec(path.buf, path.len,
1830 pathspec)))
1827 - dir_add_ignored(dir, path.buf, path.len);
1831 + dir_add_ignored(dir, &the_index, path.buf, path.len);
1832 break;
1833
1834 case path_untracked:
1835 if (dir->flags & DIR_SHOW_IGNORED)
1836 break;
1833 - dir_add_name(dir, path.buf, path.len);
1837 + dir_add_name(dir, &the_index, path.buf, path.len);
1838 if (cdir.fdir)
1839 add_untracked(untracked, path.buf + baselen);
1840 break;
dir.h
+3 -1
@@ -219,7 +219,9 @@ extern int read_directory(struct dir_struct *, const char *path, int len, const
219
220 extern int is_excluded_from_list(const char *pathname, int pathlen, const char *basename,
221 int *dtype, struct exclude_list *el);
222 -struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len);
222 +struct dir_entry *dir_add_ignored(struct dir_struct *dir,
223 + struct index_state *istate,
224 + const char *pathname, int len);
225
226 /*
227 * these implement the matching logic for dir.c:excluded_from_list and