Skip to content

Commit 4888c53

Browse files
author
Junio C Hamano
committed
read_directory: show_both option.
This teaches the internal read_directory() routine to return both interesting and ignored pathnames. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 08d2248 commit 4888c53

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

dir.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ int excluded(struct dir_struct *dir, const char *pathname)
260260
return 0;
261261
}
262262

263-
static void add_name(struct dir_struct *dir, const char *pathname, int len)
263+
static void add_name(struct dir_struct *dir, const char *pathname, int len,
264+
int ignored_entry)
264265
{
265266
struct dir_entry *ent;
266267

@@ -273,6 +274,7 @@ static void add_name(struct dir_struct *dir, const char *pathname, int len)
273274
dir->entries = xrealloc(dir->entries, alloc*sizeof(ent));
274275
}
275276
ent = xmalloc(sizeof(*ent) + len + 1);
277+
ent->ignored_entry = ignored_entry;
276278
ent->len = len;
277279
memcpy(ent->name, pathname, len);
278280
ent->name[len] = 0;
@@ -314,6 +316,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
314316

315317
while ((de = readdir(fdir)) != NULL) {
316318
int len;
319+
int ignored_entry;
317320

318321
if ((de->d_name[0] == '.') &&
319322
(de->d_name[1] == 0 ||
@@ -322,11 +325,12 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
322325
continue;
323326
len = strlen(de->d_name);
324327
memcpy(fullname + baselen, de->d_name, len+1);
325-
if (excluded(dir, fullname) != dir->show_ignored) {
326-
if (!dir->show_ignored || DTYPE(de) != DT_DIR) {
327-
continue;
328-
}
329-
}
328+
ignored_entry = excluded(dir, fullname);
329+
330+
if (!dir->show_both &&
331+
(ignored_entry != dir->show_ignored) &&
332+
(!dir->show_ignored || DTYPE(de) != DT_DIR))
333+
continue;
330334

331335
switch (DTYPE(de)) {
332336
struct stat st;
@@ -364,7 +368,8 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
364368
if (check_only)
365369
goto exit_early;
366370
else
367-
add_name(dir, fullname, baselen + len);
371+
add_name(dir, fullname, baselen + len,
372+
ignored_entry);
368373
}
369374
exit_early:
370375
closedir(fdir);

dir.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414

1515
struct dir_entry {
16-
int len;
16+
unsigned ignored_entry : 1;
17+
unsigned int len : 15;
1718
char name[FLEX_ARRAY]; /* more */
1819
};
1920

@@ -29,7 +30,8 @@ struct exclude_list {
2930

3031
struct dir_struct {
3132
int nr, alloc;
32-
unsigned int show_ignored:1,
33+
unsigned int show_both: 1,
34+
show_ignored:1,
3335
show_other_directories:1,
3436
hide_empty_directories:1;
3537
struct dir_entry **entries;

0 commit comments

Comments
 (0)