summaryrefslogtreecommitdiff
path: root/worktree.c
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2021-05-12 17:28:22 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-05-12 23:45:03 (GMT)
commitb548f0f1568f6b01e55ca69c24d3cb19489f92aa (patch)
tree0a6c2580b275d3565b5a8de558fa4e49fbed1fb5 /worktree.c
parent4e689d81718eb6e939cace317ea3e33cb994dcbb (diff)
downloadgit-b548f0f1568f6b01e55ca69c24d3cb19489f92aa.zip
git-b548f0f1568f6b01e55ca69c24d3cb19489f92aa.tar.gz
git-b548f0f1568f6b01e55ca69c24d3cb19489f92aa.tar.bz2
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 'worktree.c')
-rw-r--r--worktree.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/worktree.c b/worktree.c
index f35ac40..237517b 100644
--- a/worktree.c
+++ b/worktree.c
@@ -128,10 +128,8 @@ struct worktree **get_worktrees(void)
dir = opendir(path.buf);
strbuf_release(&path);
if (dir) {
- while ((d = readdir(dir)) != NULL) {
+ while ((d = readdir_skip_dot_and_dotdot(dir)) != NULL) {
struct worktree *linked = NULL;
- if (is_dot_or_dotdot(d->d_name))
- continue;
if ((linked = get_linked_worktree(d->d_name))) {
ALLOC_GROW(list, counter + 1, alloc);
@@ -486,13 +484,9 @@ int submodule_uses_worktrees(const char *path)
if (!dir)
return 0;
- while ((d = readdir(dir)) != NULL) {
- if (is_dot_or_dotdot(d->d_name))
- continue;
-
+ d = readdir_skip_dot_and_dotdot(dir);
+ if (d != NULL)
ret = 1;
- break;
- }
closedir(dir);
return ret;
}