summaryrefslogtreecommitdiffstats
path: root/dir-iterator.h
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-02-21 13:37:23 +0100
committerJunio C Hamano <gitster@pobox.com>2024-02-21 18:58:05 +0100
commitde34f2651ecca00dffeb61934253345150a1cc32 (patch)
tree379ff14c99ee3f5ad4ecbbdb07fe8e30ff64bdb5 /dir-iterator.h
parentdir-iterator: pass name to `prepare_next_entry_data()` directly (diff)
downloadgit-de34f2651ecca00dffeb61934253345150a1cc32.tar.xz
git-de34f2651ecca00dffeb61934253345150a1cc32.zip
dir-iterator: support iteration in sorted order
The `struct dir_iterator` is a helper that allows us to iterate through directory entries. This iterator returns entries in the exact same order as readdir(3P) does -- or in other words, it guarantees no specific order at all. This is about to become problematic as we are introducing a new reflog subcommand to list reflogs. As the "files" backend uses the directory iterator to enumerate reflogs, returning reflog names and exposing them to the user would inherit the indeterministic ordering. Naturally, it would make for a terrible user interface to show a list with no discernible order. While this could be handled at a higher level by the new subcommand itself by collecting and ordering the reflogs, this would be inefficient because we would first have to collect all reflogs before we can sort them, which would introduce additional latency when there are many reflogs. Instead, introduce a new option into the directory iterator that asks for its entries to be yielded in lexicographical order. If set, the iterator will read all directory entries greedily and sort them before we start to iterate over them. While this will of course also incur overhead as we cannot yield the directory entries immediately, it should at least be more efficient than having to sort the complete list of reflogs as we only need to sort one directory at a time. This functionality will be used in a follow-up commit. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir-iterator.h')
-rw-r--r--dir-iterator.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/dir-iterator.h b/dir-iterator.h
index 479e1ec784..6d438809b6 100644
--- a/dir-iterator.h
+++ b/dir-iterator.h
@@ -54,8 +54,11 @@
* and ITER_ERROR is returned immediately. In both cases, a meaningful
* warning is emitted. Note: ENOENT errors are always ignored so that
* the API users may remove files during iteration.
+ *
+ * - DIR_ITERATOR_SORTED: sort directory entries alphabetically.
*/
#define DIR_ITERATOR_PEDANTIC (1 << 0)
+#define DIR_ITERATOR_SORTED (1 << 1)
struct dir_iterator {
/* The current path: */