diff options
author | Elijah Newren <newren@gmail.com> | 2021-05-12 19:28:22 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-05-13 01:45:03 +0200 |
commit | b548f0f1568f6b01e55ca69c24d3cb19489f92aa (patch) | |
tree | 0a6c2580b275d3565b5a8de558fa4e49fbed1fb5 /diff-no-index.c | |
parent | dir: update stale description of treat_directory() (diff) | |
download | git-b548f0f1568f6b01e55ca69c24d3cb19489f92aa.tar.xz git-b548f0f1568f6b01e55ca69c24d3cb19489f92aa.zip |
dir: introduce readdir_skip_dot_and_dotdot() helper
Many places in the code were doing
while ((d = readdir(dir)) != NULL) {
if (is_dot_or_dotdot(d->d_name))
continue;
...process d...
}
Introduce a readdir_skip_dot_and_dotdot() helper to make that a one-liner:
while ((d = readdir_skip_dot_and_dotdot(dir)) != NULL) {
...process d...
}
This helper particularly simplifies checks for empty directories.
Also use this helper in read_cached_dir() so that our statistics are
consistent across platforms. (In other words, read_cached_dir() should
have been using is_dot_or_dotdot() and skipping such entries, but did
not and left it to treat_path() to detect and mark such entries as
path_none.)
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff-no-index.c')
-rw-r--r-- | diff-no-index.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/diff-no-index.c b/diff-no-index.c index 7814eabfe0..e5cc878371 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -26,9 +26,8 @@ static int read_directory_contents(const char *path, struct string_list *list) if (!(dir = opendir(path))) return error("Could not open directory %s", path); - while ((e = readdir(dir))) - if (!is_dot_or_dotdot(e->d_name)) - string_list_insert(list, e->d_name); + while ((e = readdir_skip_dot_and_dotdot(dir))) + string_list_insert(list, e->d_name); closedir(dir); return 0; |