Revert "dir: introduce readdir_skip_dot_and_dotdot() helper"

This reverts commit b548f0f1568f6b01e55ca69c24d3cb19489f92aa, to be replaced with a reworked version.

Junio C Hamano committed May 27, 2021 at 13:59 UTC 1df046bcff6085f3800088c51e344594f822df57
11 files changed +45 -31
builtin/clean.c
+3 -1
@@ -189,8 +189,10 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
189 strbuf_complete(path, '/');
190
191 len = path->len;
192 - while ((e = readdir_skip_dot_and_dotdot(dir)) != NULL) {
192 + while ((e = readdir(dir)) != NULL) {
193 struct stat st;
194 + if (is_dot_or_dotdot(e->d_name))
195 + continue;
196
197 strbuf_setlen(path, len);
198 strbuf_addstr(path, e->d_name);
builtin/worktree.c
+3 -1
@@ -118,8 +118,10 @@ static void prune_worktrees(void)
118 struct dirent *d;
119 if (!dir)
120 return;
121 - while ((d = readdir_skip_dot_and_dotdot(dir)) != NULL) {
121 + while ((d = readdir(dir)) != NULL) {
122 char *path;
123 + if (is_dot_or_dotdot(d->d_name))
124 + continue;
125 strbuf_reset(&reason);
126 if (should_prune_worktree(d->d_name, &reason, &path, expire))
127 prune_worktree(d->d_name, reason.buf);
diff-no-index.c
+3 -2
@@ -26,8 +26,9 @@ static int read_directory_contents(const char *path, struct string_list *list)
26 if (!(dir = opendir(path)))
27 return error("Could not open directory %s", path);
28
29 - while ((e = readdir_skip_dot_and_dotdot(dir)))
30 - string_list_insert(list, e->d_name);
29 + while ((e = readdir(dir)))
30 + if (!is_dot_or_dotdot(e->d_name))
31 + string_list_insert(list, e->d_name);
32
33 closedir(dir);
34 return 0;
dir.c
+9 -17
@@ -59,18 +59,6 @@ void dir_init(struct dir_struct *dir)
59 memset(dir, 0, sizeof(*dir));
60 }
61
62 -struct dirent *
63 -readdir_skip_dot_and_dotdot(DIR *dirp)
64 -{
65 - struct dirent *e;
66 -
67 - while ((e = readdir(dirp)) != NULL) {
68 - if (!is_dot_or_dotdot(e->d_name))
69 - break;
70 - }
71 - return e;
72 -}
73 -
62 int count_slashes(const char *s)
63 {
64 int cnt = 0;
@@ -2344,7 +2332,7 @@ static int read_cached_dir(struct cached_dir *cdir)
2332 struct dirent *de;
2333
2334 if (cdir->fdir) {
2347 - de = readdir_skip_dot_and_dotdot(cdir->fdir);
2335 + de = readdir(cdir->fdir);
2336 if (!de) {
2337 cdir->d_name = NULL;
2338 cdir->d_type = DT_UNKNOWN;
@@ -2943,9 +2931,11 @@ int is_empty_dir(const char *path)
2931 if (!dir)
2932 return 0;
2933
2946 - e = readdir_skip_dot_and_dotdot(dir);
2947 - if (e)
2948 - ret = 0;
2934 + while ((e = readdir(dir)) != NULL)
2935 + if (!is_dot_or_dotdot(e->d_name)) {
2936 + ret = 0;
2937 + break;
2938 + }
2939
2940 closedir(dir);
2941 return ret;
@@ -2985,8 +2975,10 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up)
2975 strbuf_complete(path, '/');
2976
2977 len = path->len;
2988 - while ((e = readdir_skip_dot_and_dotdot(dir)) != NULL) {
2978 + while ((e = readdir(dir)) != NULL) {
2979 struct stat st;
2980 + if (is_dot_or_dotdot(e->d_name))
2981 + continue;
2982
2983 strbuf_setlen(path, len);
2984 strbuf_addstr(path, e->d_name);
dir.h
-2
@@ -342,8 +342,6 @@ struct dir_struct {
342 unsigned visited_directories;
343 };
344
345 -struct dirent *readdir_skip_dot_and_dotdot(DIR *dirp);
346 -
345 /*Count the number of slashes for string s*/
346 int count_slashes(const char *s);
347
entry.c
+4 -1
@@ -56,9 +56,12 @@ static void remove_subtree(struct strbuf *path)
56
57 if (!dir)
58 die_errno("cannot opendir '%s'", path->buf);
59 - while ((de = readdir_skip_dot_and_dotdot(dir)) != NULL) {
59 + while ((de = readdir(dir)) != NULL) {
60 struct stat st;
61
62 + if (is_dot_or_dotdot(de->d_name))
63 + continue;
64 +
65 strbuf_addch(path, '/');
66 strbuf_addstr(path, de->d_name);
67 if (lstat(path->buf, &st))
notes-merge.c
+4 -1
@@ -695,10 +695,13 @@ int notes_merge_commit(struct notes_merge_options *o,
695
696 strbuf_addch(&path, '/');
697 baselen = path.len;
698 - while ((e = readdir_skip_dot_and_dotdot(dir)) != NULL) {
698 + while ((e = readdir(dir)) != NULL) {
699 struct stat st;
700 struct object_id obj_oid, blob_oid;
701
702 + if (is_dot_or_dotdot(e->d_name))
703 + continue;
704 +
705 if (get_oid_hex(e->d_name, &obj_oid)) {
706 if (o->verbosity >= 3)
707 printf("Skipping non-SHA1 entry '%s%s'\n",
object-file.c
+3 -1
@@ -2304,8 +2304,10 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
2304 strbuf_addch(path, '/');
2305 baselen = path->len;
2306
2307 - while ((de = readdir_skip_dot_and_dotdot(dir))) {
2307 + while ((de = readdir(dir))) {
2308 size_t namelen;
2309 + if (is_dot_or_dotdot(de->d_name))
2310 + continue;
2311
2312 namelen = strlen(de->d_name);
2313 strbuf_setlen(path, baselen);
packfile.c
+4 -1
@@ -813,7 +813,10 @@ void for_each_file_in_pack_dir(const char *objdir,
813 }
814 strbuf_addch(&path, '/');
815 dirnamelen = path.len;
816 - while ((de = readdir_skip_dot_and_dotdot(dir)) != NULL) {
816 + while ((de = readdir(dir)) != NULL) {
817 + if (is_dot_or_dotdot(de->d_name))
818 + continue;
819 +
820 strbuf_setlen(&path, dirnamelen);
821 strbuf_addstr(&path, de->d_name);
822
rerere.c
+3 -1
@@ -1190,11 +1190,13 @@ void rerere_gc(struct repository *r, struct string_list *rr)
1190 if (!dir)
1191 die_errno(_("unable to open rr-cache directory"));
1192 /* Collect stale conflict IDs ... */
1193 - while ((e = readdir_skip_dot_and_dotdot(dir))) {
1193 + while ((e = readdir(dir))) {
1194 struct rerere_dir *rr_dir;
1195 struct rerere_id id;
1196 int now_empty;
1197
1198 + if (is_dot_or_dotdot(e->d_name))
1199 + continue;
1200 if (!is_rr_cache_dirname(e->d_name))
1201 continue; /* or should we remove e->d_name? */
1202
worktree.c
+9 -3
@@ -128,8 +128,10 @@ struct worktree **get_worktrees(void)
128 dir = opendir(path.buf);
129 strbuf_release(&path);
130 if (dir) {
131 - while ((d = readdir_skip_dot_and_dotdot(dir)) != NULL) {
131 + while ((d = readdir(dir)) != NULL) {
132 struct worktree *linked = NULL;
133 + if (is_dot_or_dotdot(d->d_name))
134 + continue;
135
136 if ((linked = get_linked_worktree(d->d_name))) {
137 ALLOC_GROW(list, counter + 1, alloc);
@@ -484,9 +486,13 @@ int submodule_uses_worktrees(const char *path)
486 if (!dir)
487 return 0;
488
487 - d = readdir_skip_dot_and_dotdot(dir);
488 - if (d != NULL)
489 + while ((d = readdir(dir)) != NULL) {
490 + if (is_dot_or_dotdot(d->d_name))
491 + continue;
492 +
493 ret = 1;
494 + break;
495 + }
496 closedir(dir);
497 return ret;
498 }