]> git.ipfire.org Git - thirdparty/git.git/commit
for-each-ref: introduce a '--start-after' option
authorKarthik Nayak <karthik.188@gmail.com>
Tue, 15 Jul 2025 11:28:30 +0000 (13:28 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Jul 2025 18:54:20 +0000 (11:54 -0700)
commitdabecb9db2b25a32d72c90832f338849b665fdf9
tree365fed331a67e6105cfd1f77776593773c0ce388
parent526530a16a3c345643afb324107b4a216b8d37ff
for-each-ref: introduce a '--start-after' option

The `git-for-each-ref(1)` command is used to iterate over references
present in a repository. In large repositories with millions of
references, it would be optimal to paginate this output such that we
can start iteration from a given reference. This would avoid having to
iterate over all references from the beginning each time when paginating
through results.

The previous commit added 'seek' functionality to the reference
backends. Utilize this and expose a '--start-after' option in
'git-for-each-ref(1)'. When used, the reference iteration seeks to the
lexicographically next reference and iterates from there onward.

This enables efficient pagination workflows, where the calling script
can remember the last provided reference and use that as the starting
point for the next set of references:
    git for-each-ref --count=100
    git for-each-ref --count=100 --start-after=refs/heads/branch-100
    git for-each-ref --count=100 --start-after=refs/heads/branch-200

Since the reference iterators only allow seeking to a specified marker
via the `ref_iterator_seek()`, we introduce a helper function
`start_ref_iterator_after()`, which seeks to next reference by simply
adding (char) 1 to the marker.

We must note that pagination always continues from the provided marker,
as such any concurrent reference updates lexicographically behind the
marker will not be output. Document the same.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-for-each-ref.adoc
builtin/for-each-ref.c
ref-filter.c
ref-filter.h
t/t6302-for-each-ref-filter.sh