Skip to content

Commit 0218de2

Browse files
pks-tgitster
authored andcommitted
dir-iterator: pass name to prepare_next_entry_data() directly
When adding the next directory entry for `struct dir_iterator` we pass the complete `struct dirent *` to `prepare_next_entry_data()` even though we only need the entry's name. Refactor the code to pass in the name, only. This prepares for a subsequent commit where we introduce the ability to iterate through dir entries in an ordered manner. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f7cdeaf commit 0218de2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

dir-iterator.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ static int pop_level(struct dir_iterator_int *iter)
9494

9595
/*
9696
* Populate iter->base with the necessary information on the next iteration
97-
* entry, represented by the given dirent de. Return 0 on success and -1
97+
* entry, represented by the given name. Return 0 on success and -1
9898
* otherwise, setting errno accordingly.
9999
*/
100100
static int prepare_next_entry_data(struct dir_iterator_int *iter,
101-
struct dirent *de)
101+
const char *name)
102102
{
103103
int err, saved_errno;
104104

105-
strbuf_addstr(&iter->base.path, de->d_name);
105+
strbuf_addstr(&iter->base.path, name);
106106
/*
107107
* We have to reset these because the path strbuf might have
108108
* been realloc()ed at the previous strbuf_addstr().
@@ -159,7 +159,7 @@ int dir_iterator_advance(struct dir_iterator *dir_iterator)
159159
if (is_dot_or_dotdot(de->d_name))
160160
continue;
161161

162-
if (prepare_next_entry_data(iter, de)) {
162+
if (prepare_next_entry_data(iter, de->d_name)) {
163163
if (errno != ENOENT && iter->flags & DIR_ITERATOR_PEDANTIC)
164164
goto error_out;
165165
continue;

0 commit comments

Comments
 (0)