Skip to content

Commit a0bba65

Browse files
bmwillgitster
authored andcommitted
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>
1 parent e799ed4 commit a0bba65

File tree

7 files changed

+19
-13
lines changed

7 files changed

+19
-13
lines changed

builtin/add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
436436
!file_exists(path))) {
437437
if (ignore_missing) {
438438
int dtype = DT_UNKNOWN;
439-
if (is_excluded(&dir, path, &dtype))
439+
if (is_excluded(&dir, &the_index, path, &dtype))
440440
dir_add_ignored(&dir, &the_index,
441441
path, pathspec.items[i].len);
442442
} else

builtin/check-ignore.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ static int check_ignore(struct dir_struct *dir,
101101
full_path = pathspec.items[i].match;
102102
exclude = NULL;
103103
if (!seen[i]) {
104-
exclude = last_exclude_matching(dir, full_path, &dtype);
104+
exclude = last_exclude_matching(dir, &the_index,
105+
full_path, &dtype);
105106
}
106107
if (!quiet && (exclude || show_non_matching))
107108
output_exclude(pathspec.items[i].original, exclude);

builtin/clean.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ static int filter_by_patterns_cmd(void)
683683
for_each_string_list_item(item, &del_list) {
684684
int dtype = DT_UNKNOWN;
685685

686-
if (is_excluded(&dir, item->string, &dtype)) {
686+
if (is_excluded(&dir, &the_index, item->string, &dtype)) {
687687
*item->string = '\0';
688688
changed++;
689689
}

builtin/ls-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static void show_ru_info(void)
322322
static int ce_excluded(struct dir_struct *dir, const struct cache_entry *ce)
323323
{
324324
int dtype = ce_to_dtype(ce);
325-
return is_excluded(dir, ce->name, &dtype);
325+
return is_excluded(dir, &the_index, ce->name, &dtype);
326326
}
327327

328328
static void show_files(struct dir_struct *dir)

dir.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,19 +1204,20 @@ static void prep_exclude(struct dir_struct *dir,
12041204
* undecided.
12051205
*/
12061206
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)
12091210
{
12101211
int pathlen = strlen(pathname);
12111212
const char *basename = strrchr(pathname, '/');
12121213
basename = (basename) ? basename+1 : pathname;
12131214

1214-
prep_exclude(dir, &the_index, pathname, basename-pathname);
1215+
prep_exclude(dir, istate, pathname, basename-pathname);
12151216

12161217
if (dir->exclude)
12171218
return dir->exclude;
12181219

1219-
return last_exclude_matching_from_lists(dir, &the_index, pathname, pathlen,
1220+
return last_exclude_matching_from_lists(dir, istate, pathname, pathlen,
12201221
basename, dtype_p);
12211222
}
12221223

@@ -1225,10 +1226,11 @@ struct exclude *last_exclude_matching(struct dir_struct *dir,
12251226
* scans all exclude lists to determine whether pathname is excluded.
12261227
* Returns 1 if true, otherwise 0.
12271228
*/
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)
12291231
{
12301232
struct exclude *exclude =
1231-
last_exclude_matching(dir, pathname, dtype_p);
1233+
last_exclude_matching(dir, istate, pathname, dtype_p);
12321234
if (exclude)
12331235
return exclude->flags & EXC_FLAG_NEGATIVE ? 0 : 1;
12341236
return 0;
@@ -1573,7 +1575,7 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
15731575
(directory_exists_in_index(&the_index, path->buf, path->len) == index_nonexistent))
15741576
return path_none;
15751577

1576-
exclude = is_excluded(dir, path->buf, &dtype);
1578+
exclude = is_excluded(dir, &the_index, path->buf, &dtype);
15771579

15781580
/*
15791581
* Excluded? If we don't explicitly want to show

dir.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,12 @@ extern int match_pathname(const char *, int,
236236
const char *, int, int, unsigned);
237237

238238
extern struct exclude *last_exclude_matching(struct dir_struct *dir,
239+
struct index_state *istate,
239240
const char *name, int *dtype);
240241

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);
242245

243246
extern struct exclude_list *add_exclude_list(struct dir_struct *dir,
244247
int group_type, const char *src);

unpack-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
16341634
return 0;
16351635

16361636
if (o->dir &&
1637-
is_excluded(o->dir, name, &dtype))
1637+
is_excluded(o->dir, &the_index, name, &dtype))
16381638
/*
16391639
* ce->name is explicitly excluded, so it is Ok to
16401640
* overwrite it.

0 commit comments

Comments
 (0)