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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Feb 21, 2024 at 13:37 UTC 0218de2bdbd13975c31c3944775d0d7a6cd73e7b
1 file changed +4 -4
dir-iterator.c
+4 -4
@@ -94,15 +94,15 @@ static int pop_level(struct dir_iterator_int *iter)
94
95 /*
96 * 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
98 * otherwise, setting errno accordingly.
99 */
100 static int prepare_next_entry_data(struct dir_iterator_int *iter,
101 - struct dirent *de)
101 + const char *name)
102 {
103 int err, saved_errno;
104
105 - strbuf_addstr(&iter->base.path, de->d_name);
105 + strbuf_addstr(&iter->base.path, name);
106 /*
107 * We have to reset these because the path strbuf might have
108 * been realloc()ed at the previous strbuf_addstr().
@@ -159,7 +159,7 @@ int dir_iterator_advance(struct dir_iterator *dir_iterator)
159 if (is_dot_or_dotdot(de->d_name))
160 continue;
161
162 - if (prepare_next_entry_data(iter, de)) {
162 + if (prepare_next_entry_data(iter, de->d_name)) {
163 if (errno != ENOENT && iter->flags & DIR_ITERATOR_PEDANTIC)
164 goto error_out;
165 continue;