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>
This commit is contained in:

committed by
Junio C Hamano

parent
4e689d8171
commit
b548f0f156
@ -695,13 +695,10 @@ int notes_merge_commit(struct notes_merge_options *o,
|
||||
|
||||
strbuf_addch(&path, '/');
|
||||
baselen = path.len;
|
||||
while ((e = readdir(dir)) != NULL) {
|
||||
while ((e = readdir_skip_dot_and_dotdot(dir)) != NULL) {
|
||||
struct stat st;
|
||||
struct object_id obj_oid, blob_oid;
|
||||
|
||||
if (is_dot_or_dotdot(e->d_name))
|
||||
continue;
|
||||
|
||||
if (get_oid_hex(e->d_name, &obj_oid)) {
|
||||
if (o->verbosity >= 3)
|
||||
printf("Skipping non-SHA1 entry '%s%s'\n",
|
||||
|
Reference in New Issue
Block a user