Skip to content

Commit 9e58bec

Browse files
bmwillgitster
authored andcommitted
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>
1 parent 98f2a68 commit 9e58bec

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

builtin/add.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
437437
if (ignore_missing) {
438438
int dtype = DT_UNKNOWN;
439439
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);
441442
} else
442443
die(_("pathspec '%s' did not match any files"),
443444
pathspec.items[i].original);

dir.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,18 +1236,22 @@ static struct dir_entry *dir_entry_new(const char *pathname, int len)
12361236
return ent;
12371237
}
12381238

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)
12401242
{
1241-
if (index_file_exists(&the_index, pathname, len, ignore_case))
1243+
if (index_file_exists(istate, pathname, len, ignore_case))
12421244
return NULL;
12431245

12441246
ALLOC_GROW(dir->entries, dir->nr+1, dir->alloc);
12451247
return dir->entries[dir->nr++] = dir_entry_new(pathname, len);
12461248
}
12471249

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)
12491253
{
1250-
if (!index_name_is_other(&the_index, pathname, len))
1254+
if (!index_name_is_other(istate, pathname, len))
12511255
return NULL;
12521256

12531257
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,
18191823
switch (state) {
18201824
case path_excluded:
18211825
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);
18231827
else if ((dir->flags & DIR_SHOW_IGNORED_TOO) ||
18241828
((dir->flags & DIR_COLLECT_IGNORED) &&
18251829
exclude_matches_pathspec(path.buf, path.len,
18261830
pathspec)))
1827-
dir_add_ignored(dir, path.buf, path.len);
1831+
dir_add_ignored(dir, &the_index, path.buf, path.len);
18281832
break;
18291833

18301834
case path_untracked:
18311835
if (dir->flags & DIR_SHOW_IGNORED)
18321836
break;
1833-
dir_add_name(dir, path.buf, path.len);
1837+
dir_add_name(dir, &the_index, path.buf, path.len);
18341838
if (cdir.fdir)
18351839
add_untracked(untracked, path.buf + baselen);
18361840
break;

dir.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ extern int read_directory(struct dir_struct *, const char *path, int len, const
219219

220220
extern int is_excluded_from_list(const char *pathname, int pathlen, const char *basename,
221221
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);
223225

224226
/*
225227
* these implement the matching logic for dir.c:excluded_from_list and

0 commit comments

Comments
 (0)