Skip to content

Commit b07bc8c

Browse files
kbleesgitster
authored andcommitted
dir.c: replace is_path_excluded with now equivalent is_excluded API
Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 95c6f27 commit b07bc8c

File tree

7 files changed

+16
-116
lines changed

7 files changed

+16
-116
lines changed

builtin/add.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,25 +444,22 @@ int cmd_add(int argc, const char **argv, const char *prefix)
444444

445445
if (pathspec) {
446446
int i;
447-
struct path_exclude_check check;
448447

449-
path_exclude_check_init(&check, &dir);
450448
if (!seen)
451449
seen = find_pathspecs_matching_against_index(pathspec);
452450
for (i = 0; pathspec[i]; i++) {
453451
if (!seen[i] && pathspec[i][0]
454452
&& !file_exists(pathspec[i])) {
455453
if (ignore_missing) {
456454
int dtype = DT_UNKNOWN;
457-
if (is_path_excluded(&check, pathspec[i], -1, &dtype))
455+
if (is_excluded(&dir, pathspec[i], &dtype))
458456
dir_add_ignored(&dir, pathspec[i], strlen(pathspec[i]));
459457
} else
460458
die(_("pathspec '%s' did not match any files"),
461459
pathspec[i]);
462460
}
463461
}
464462
free(seen);
465-
path_exclude_check_clear(&check);
466463
}
467464

468465
plug_bulk_checkin();

builtin/check-ignore.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ static int check_ignore(const char *prefix, const char **pathspec)
5959
const char *path, *full_path;
6060
char *seen;
6161
int num_ignored = 0, dtype = DT_UNKNOWN, i;
62-
struct path_exclude_check check;
6362
struct exclude *exclude;
6463

6564
/* 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)
7675
return 0;
7776
}
7877

79-
path_exclude_check_init(&check, &dir);
8078
/*
8179
* look for pathspecs matching entries in the index, since these
8280
* should not be ignored, in order to be consistent with
@@ -90,8 +88,7 @@ static int check_ignore(const char *prefix, const char **pathspec)
9088
full_path = check_path_for_gitlink(full_path);
9189
die_if_path_beyond_symlink(full_path, prefix);
9290
if (!seen[i]) {
93-
exclude = last_exclude_matching_path(&check, full_path,
94-
-1, &dtype);
91+
exclude = last_exclude_matching(&dir, full_path, &dtype);
9592
if (exclude) {
9693
if (!quiet)
9794
output_exclude(path, exclude);
@@ -101,7 +98,6 @@ static int check_ignore(const char *prefix, const char **pathspec)
10198
}
10299
free(seen);
103100
clear_directory(&dir);
104-
path_exclude_check_clear(&check);
105101

106102
return num_ignored;
107103
}

builtin/ls-files.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,15 @@ static void show_ru_info(void)
201201
}
202202
}
203203

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)
205205
{
206206
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);
208208
}
209209

210210
static void show_files(struct dir_struct *dir)
211211
{
212212
int i;
213-
struct path_exclude_check check;
214-
215-
if ((dir->flags & DIR_SHOW_IGNORED))
216-
path_exclude_check_init(&check, dir);
217213

218214
/* For cached/deleted files we don't need to even do the readdir */
219215
if (show_others || show_killed) {
@@ -227,7 +223,7 @@ static void show_files(struct dir_struct *dir)
227223
for (i = 0; i < active_nr; i++) {
228224
struct cache_entry *ce = active_cache[i];
229225
if ((dir->flags & DIR_SHOW_IGNORED) &&
230-
!ce_excluded(&check, ce))
226+
!ce_excluded(dir, ce))
231227
continue;
232228
if (show_unmerged && !ce_stage(ce))
233229
continue;
@@ -243,7 +239,7 @@ static void show_files(struct dir_struct *dir)
243239
struct stat st;
244240
int err;
245241
if ((dir->flags & DIR_SHOW_IGNORED) &&
246-
!ce_excluded(&check, ce))
242+
!ce_excluded(dir, ce))
247243
continue;
248244
if (ce->ce_flags & CE_UPDATE)
249245
continue;
@@ -256,9 +252,6 @@ static void show_files(struct dir_struct *dir)
256252
show_ce_entry(tag_modified, ce);
257253
}
258254
}
259-
260-
if ((dir->flags & DIR_SHOW_IGNORED))
261-
path_exclude_check_clear(&check);
262255
}
263256

264257
/*

dir.c

Lines changed: 6 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
843843
* Returns the exclude_list element which matched, or NULL for
844844
* undecided.
845845
*/
846-
static struct exclude *last_exclude_matching(struct dir_struct *dir,
846+
struct exclude *last_exclude_matching(struct dir_struct *dir,
847847
const char *pathname,
848848
int *dtype_p)
849849
{
@@ -865,7 +865,7 @@ static struct exclude *last_exclude_matching(struct dir_struct *dir,
865865
* scans all exclude lists to determine whether pathname is excluded.
866866
* Returns 1 if true, otherwise 0.
867867
*/
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)
869869
{
870870
struct exclude *exclude =
871871
last_exclude_matching(dir, pathname, dtype_p);
@@ -874,47 +874,6 @@ static int is_excluded(struct dir_struct *dir, const char *pathname, int *dtype_
874874
return 0;
875875
}
876876

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-
918877
static struct dir_entry *dir_entry_new(const char *pathname, int len)
919878
{
920879
struct dir_entry *ent;
@@ -1086,15 +1045,6 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
10861045

10871046
/* This is the "show_other_directories" case */
10881047

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-
10981048
/*
10991049
* We are looking for ignored files and our directory is not ignored,
11001050
* 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,
11291079
*
11301080
* Return 1 for exclude, 0 for include.
11311081
*/
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)
11331083
{
1134-
struct path_exclude_check check;
1135-
int exclude_file = 0;
1136-
11371084
/* Always exclude indexed files */
11381085
if (index_name_exists(&the_index, path->buf, path->len, ignore_case))
11391086
return 1;
11401087

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);
11531089
}
11541090

11551091
/*
@@ -1306,12 +1242,9 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
13061242
break;
13071243
case DT_REG:
13081244
case DT_LNK:
1309-
switch (treat_file(dir, path, exclude, &dtype)) {
1310-
case 1:
1245+
if (treat_file(dir, path, exclude))
13111246
return path_ignored;
1312-
default:
1313-
break;
1314-
}
1247+
break;
13151248
}
13161249
return path_handled;
13171250
}

dir.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,10 @@ extern int match_pathname(const char *, int,
151151
const char *, int,
152152
const char *, int, int, int);
153153

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

157+
extern int is_excluded(struct dir_struct *dir, const char *name, int *dtype);
168158

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

unpack-trees.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,10 +1026,6 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
10261026
o->el = &el;
10271027
}
10281028

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-
}
10331029
memset(&o->result, 0, sizeof(o->result));
10341030
o->result.initialized = 1;
10351031
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
11551151

11561152
done:
11571153
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-
}
11621154
return ret;
11631155

11641156
return_failed:
@@ -1375,7 +1367,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
13751367
return 0;
13761368

13771369
if (o->dir &&
1378-
is_path_excluded(o->path_exclude_check, name, -1, &dtype))
1370+
is_excluded(o->dir, name, &dtype))
13791371
/*
13801372
* ce->name is explicitly excluded, so it is Ok to
13811373
* overwrite it.

unpack-trees.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ struct unpack_trees_options {
5252
const char *prefix;
5353
int cache_bottom;
5454
struct dir_struct *dir;
55-
struct path_exclude_check *path_exclude_check;
5655
struct pathspec *pathspec;
5756
merge_fn_t fn;
5857
const char *msgs[NB_UNPACK_TREES_ERROR_TYPES];

0 commit comments

Comments
 (0)