https://github.com/git/git
Revision 906fc557b70b2b2995785c9b37e212d2f86b469e authored by Elijah Newren on 27 May 2021, 04:53:56 UTC, committed by Junio C Hamano on 27 May 2021, 05:02:37 UTC
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>
1 parent eef8148
History
Tip revision: 906fc557b70b2b2995785c9b37e212d2f86b469e authored by Elijah Newren on 27 May 2021, 04:53:56 UTC
dir: introduce readdir_skip_dot_and_dotdot() helper
Tip revision: 906fc55
File Mode Size
sha1.c -rw-r--r-- 7.3 KB
sha1.h -rw-r--r-- 705 bytes

back to top