Skip to content

Commit 1df046b

Browse files
committed
Revert "dir: introduce readdir_skip_dot_and_dotdot() helper"
This reverts commit b548f0f, to be replaced with a reworked version.
1 parent b548f0f commit 1df046b

File tree

11 files changed

+45
-31
lines changed

11 files changed

+45
-31
lines changed

builtin/clean.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,10 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
189189
strbuf_complete(path, '/');
190190

191191
len = path->len;
192-
while ((e = readdir_skip_dot_and_dotdot(dir)) != NULL) {
192+
while ((e = readdir(dir)) != NULL) {
193193
struct stat st;
194+
if (is_dot_or_dotdot(e->d_name))
195+
continue;
194196

195197
strbuf_setlen(path, len);
196198
strbuf_addstr(path, e->d_name);

builtin/worktree.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ static void prune_worktrees(void)
118118
struct dirent *d;
119119
if (!dir)
120120
return;
121-
while ((d = readdir_skip_dot_and_dotdot(dir)) != NULL) {
121+
while ((d = readdir(dir)) != NULL) {
122122
char *path;
123+
if (is_dot_or_dotdot(d->d_name))
124+
continue;
123125
strbuf_reset(&reason);
124126
if (should_prune_worktree(d->d_name, &reason, &path, expire))
125127
prune_worktree(d->d_name, reason.buf);

diff-no-index.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ static int read_directory_contents(const char *path, struct string_list *list)
2626
if (!(dir = opendir(path)))
2727
return error("Could not open directory %s", path);
2828

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);
3132

3233
closedir(dir);
3334
return 0;

dir.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,6 @@ void dir_init(struct dir_struct *dir)
5959
memset(dir, 0, sizeof(*dir));
6060
}
6161

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-
7462
int count_slashes(const char *s)
7563
{
7664
int cnt = 0;
@@ -2344,7 +2332,7 @@ static int read_cached_dir(struct cached_dir *cdir)
23442332
struct dirent *de;
23452333

23462334
if (cdir->fdir) {
2347-
de = readdir_skip_dot_and_dotdot(cdir->fdir);
2335+
de = readdir(cdir->fdir);
23482336
if (!de) {
23492337
cdir->d_name = NULL;
23502338
cdir->d_type = DT_UNKNOWN;
@@ -2943,9 +2931,11 @@ int is_empty_dir(const char *path)
29432931
if (!dir)
29442932
return 0;
29452933

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+
}
29492939

29502940
closedir(dir);
29512941
return ret;
@@ -2985,8 +2975,10 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up)
29852975
strbuf_complete(path, '/');
29862976

29872977
len = path->len;
2988-
while ((e = readdir_skip_dot_and_dotdot(dir)) != NULL) {
2978+
while ((e = readdir(dir)) != NULL) {
29892979
struct stat st;
2980+
if (is_dot_or_dotdot(e->d_name))
2981+
continue;
29902982

29912983
strbuf_setlen(path, len);
29922984
strbuf_addstr(path, e->d_name);

dir.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,6 @@ struct dir_struct {
342342
unsigned visited_directories;
343343
};
344344

345-
struct dirent *readdir_skip_dot_and_dotdot(DIR *dirp);
346-
347345
/*Count the number of slashes for string s*/
348346
int count_slashes(const char *s);
349347

entry.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ static void remove_subtree(struct strbuf *path)
5656

5757
if (!dir)
5858
die_errno("cannot opendir '%s'", path->buf);
59-
while ((de = readdir_skip_dot_and_dotdot(dir)) != NULL) {
59+
while ((de = readdir(dir)) != NULL) {
6060
struct stat st;
6161

62+
if (is_dot_or_dotdot(de->d_name))
63+
continue;
64+
6265
strbuf_addch(path, '/');
6366
strbuf_addstr(path, de->d_name);
6467
if (lstat(path->buf, &st))

notes-merge.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,13 @@ int notes_merge_commit(struct notes_merge_options *o,
695695

696696
strbuf_addch(&path, '/');
697697
baselen = path.len;
698-
while ((e = readdir_skip_dot_and_dotdot(dir)) != NULL) {
698+
while ((e = readdir(dir)) != NULL) {
699699
struct stat st;
700700
struct object_id obj_oid, blob_oid;
701701

702+
if (is_dot_or_dotdot(e->d_name))
703+
continue;
704+
702705
if (get_oid_hex(e->d_name, &obj_oid)) {
703706
if (o->verbosity >= 3)
704707
printf("Skipping non-SHA1 entry '%s%s'\n",

object-file.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2304,8 +2304,10 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
23042304
strbuf_addch(path, '/');
23052305
baselen = path->len;
23062306

2307-
while ((de = readdir_skip_dot_and_dotdot(dir))) {
2307+
while ((de = readdir(dir))) {
23082308
size_t namelen;
2309+
if (is_dot_or_dotdot(de->d_name))
2310+
continue;
23092311

23102312
namelen = strlen(de->d_name);
23112313
strbuf_setlen(path, baselen);

packfile.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,10 @@ void for_each_file_in_pack_dir(const char *objdir,
813813
}
814814
strbuf_addch(&path, '/');
815815
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+
817820
strbuf_setlen(&path, dirnamelen);
818821
strbuf_addstr(&path, de->d_name);
819822

rerere.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,11 +1190,13 @@ void rerere_gc(struct repository *r, struct string_list *rr)
11901190
if (!dir)
11911191
die_errno(_("unable to open rr-cache directory"));
11921192
/* Collect stale conflict IDs ... */
1193-
while ((e = readdir_skip_dot_and_dotdot(dir))) {
1193+
while ((e = readdir(dir))) {
11941194
struct rerere_dir *rr_dir;
11951195
struct rerere_id id;
11961196
int now_empty;
11971197

1198+
if (is_dot_or_dotdot(e->d_name))
1199+
continue;
11981200
if (!is_rr_cache_dirname(e->d_name))
11991201
continue; /* or should we remove e->d_name? */
12001202

0 commit comments

Comments
 (0)