Skip to content

Commit 2abd31b

Browse files
peffgitster
authored andcommitted
dir_struct: add collect_ignored option
When set, this option will cause read_directory to keep track of which entries were ignored. While this shouldn't effect functionality in most cases, it can make warning messages to the user much more useful. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 90ac368 commit 2abd31b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

dir.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,15 @@ struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int
291291
return dir->entries[dir->nr++] = dir_entry_new(pathname, len);
292292
}
293293

294+
struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len)
295+
{
296+
if (cache_name_pos(pathname, len) >= 0)
297+
return NULL;
298+
299+
ALLOC_GROW(dir->ignored, dir->ignored_nr, dir->ignored_alloc);
300+
return dir->ignored[dir->ignored_nr++] = dir_entry_new(pathname, len);
301+
}
302+
294303
enum exist_status {
295304
index_nonexistent = 0,
296305
index_directory,
@@ -463,6 +472,8 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
463472
continue;
464473

465474
exclude = excluded(dir, fullname);
475+
if (exclude && dir->collect_ignored)
476+
dir_add_ignored(dir, fullname, baselen + len);
466477
if (exclude != dir->show_ignored) {
467478
if (!dir->show_ignored || DTYPE(de) != DT_DIR) {
468479
continue;
@@ -609,6 +620,7 @@ int read_directory(struct dir_struct *dir, const char *path, const char *base, i
609620
read_directory_recursive(dir, path, base, baselen, 0, simplify);
610621
free_simplify(simplify);
611622
qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name);
623+
qsort(dir->ignored, dir->ignored_nr, sizeof(struct dir_entry *), cmp_name);
612624
return dir->nr;
613625
}
614626

dir.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ struct exclude_list {
3131

3232
struct dir_struct {
3333
int nr, alloc;
34+
int ignored_nr, ignored_alloc;
3435
unsigned int show_ignored:1,
3536
show_other_directories:1,
3637
hide_empty_directories:1,
37-
no_gitlinks:1;
38+
no_gitlinks:1,
39+
collect_ignored:1;
3840
struct dir_entry **entries;
41+
struct dir_entry **ignored;
3942

4043
/* Exclude info */
4144
const char *exclude_per_dir;

0 commit comments

Comments
 (0)