From: Junio C Hamano <gitster@pobox.com>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org, ps@pks.im, schwab@linux-m68k.org,
phillip.wood123@gmail.com,
Christian Couder <chriscool@tuxfamily.org>
Subject: Re: [PATCH v5 5/5] for-each-ref: introduce a '--start-after' option
Date: Thu, 17 Jul 2025 08:31:33 -0700 [thread overview]
Message-ID: <xmqqikjq7s16.fsf@gitster.g> (raw)
In-Reply-To: <20250715-306-git-for-each-ref-pagination-v5-5-852d5a2f56e1@gmail.com> (Karthik Nayak's message of "Tue, 15 Jul 2025 13:28:30 +0200")
Karthik Nayak <karthik.188@gmail.com> writes:
> 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>
> ---
> Documentation/git-for-each-ref.adoc | 10 +-
> builtin/for-each-ref.c | 8 ++
> ref-filter.c | 78 +++++++++++----
> ref-filter.h | 1 +
> t/t6302-for-each-ref-filter.sh | 194 ++++++++++++++++++++++++++++++++++++
> 5 files changed, 272 insertions(+), 19 deletions(-)
>
> diff --git a/Documentation/git-for-each-ref.adoc b/Documentation/git-for-each-ref.adoc
> index 5ef89fc0fe..ae61ba642a 100644
> --- a/Documentation/git-for-each-ref.adoc
> +++ b/Documentation/git-for-each-ref.adoc
> @@ -14,7 +14,7 @@ SYNOPSIS
> [--points-at=<object>]
> [--merged[=<object>]] [--no-merged[=<object>]]
> [--contains[=<object>]] [--no-contains[=<object>]]
> - [--exclude=<pattern> ...]
> + [--exclude=<pattern> ...] [--start-after=<marker>]
Not a problem this patch introduces, but as I noticed it, let me
leave a #leftoverbits comment here (it is OK to have a preliminary
clean-up patch).
* "--exclude=<pattern>" should be enclosed inside a pair of
(parentheses), just like the way how [(--sort=<key>)...] is
shown.
* [--stdin | <pattern>...] should be moved to the end. There is no
reason to require "--stdin" to be the end of dashed options, but
the <pattern>... must be, as they are positional, not dashed.
> +--start-after=<marker>::
> + Allows paginating the output by skipping references up to and including the
> + specified marker. When paging, it should be noted that references may be
> + deleted, modified or added between invocations. Output will only yield those
> + references which follow the marker lexicographically. Output begins from the
> + first reference that would come after the marker alphabetically. Cannot be
> + used with general pattern matching or custom sort options.
It is unclear what "general" in "general pattern matching" refers
to.
Cannot be used with `--sort=<key>` or `--stdin` options, or
the _<pattern>_ argument(s) to limit the refs.
or something, perhaps? It is curious how `--exclude=<pattern>`
interacts with the feature. Presumably the exclusion is done so
late in the output phase that it does not have any effect? It does
not have to be mentioned in this documentation if that is the case
as it is a mere implementation detail.
Side note. The limitation that sorting and name_patterns cannot
be used with the feature also comes from implementation
(i.e. the name_patterns optimization will compete with this
feature to take advantage of the "prefix" thing in an
incompatible way), so while the reason does not have to be
stated in the end-user facing documentation, the effect needs
documenting.
> @@ -3189,6 +3221,7 @@ void filter_is_base(struct repository *r,
>
> static int do_filter_refs(struct ref_filter *filter, unsigned int type, each_ref_fn fn, void *cb_data)
> {
> + const char *prefix = NULL;
> ...
> +
> + if (prefix) {
> + struct ref_iterator *iter;
> +
> + iter = refs_ref_iterator_begin(get_main_ref_store(the_repository),
> + "", NULL, 0, 0);
> +
> + if (filter->start_after)
The start_after of the filter comes from "--start-after=<mark>".
Can it be true with non-NULL prefix at this point? Unless you add
support for the option to "git branch/tag", it would not happen, I
guess.
More importantly, when you do add support to "git branch/tag", the
code need to be updated to keep the original prefix while seeking
the cursor to the specified <mark>, instead of clearing it.
> + ret = start_ref_iterator_after(iter, filter->start_after);
> + else if (prefix)
> + ret = ref_iterator_seek(iter, prefix, 1);
We have "REF_ITERATOR_SEEK_SET_PREFIX" for that "1"?
next prev parent reply other threads:[~2025-07-17 15:31 UTC|newest]
Thread overview: 102+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-01 15:03 [PATCH 0/4] for-each-ref: introduce seeking functionality via '--skip-until' Karthik Nayak
2025-07-01 15:03 ` [PATCH 1/4] refs: expose `ref_iterator` via 'refs.h' Karthik Nayak
2025-07-01 15:03 ` [PATCH 2/4] ref-cache: remove unused function 'find_ref_entry()' Karthik Nayak
2025-07-14 15:46 ` Junio C Hamano
2025-07-01 15:03 ` [PATCH 3/4] refs: selectively set prefix in the seek functions Karthik Nayak
2025-07-03 5:55 ` Patrick Steinhardt
2025-07-03 9:40 ` Karthik Nayak
2025-07-01 15:03 ` [PATCH 4/4] for-each-ref: introduce a '--skip-until' option Karthik Nayak
2025-07-03 5:55 ` Patrick Steinhardt
2025-07-03 10:02 ` Karthik Nayak
2025-07-03 10:59 ` Patrick Steinhardt
2025-07-01 17:08 ` [PATCH 0/4] for-each-ref: introduce seeking functionality via '--skip-until' Junio C Hamano
2025-07-02 16:45 ` Karthik Nayak
2025-07-01 21:37 ` Junio C Hamano
2025-07-02 18:19 ` Karthik Nayak
2025-07-03 8:41 ` Karthik Nayak
2025-07-02 14:14 ` Phillip Wood
2025-07-02 20:33 ` Karthik Nayak
2025-07-03 5:18 ` Patrick Steinhardt
2025-07-03 5:56 ` Junio C Hamano
2025-07-03 8:19 ` Patrick Steinhardt
2025-07-03 8:48 ` Karthik Nayak
2025-07-04 13:02 ` [PATCH v2 " Karthik Nayak
2025-07-04 13:02 ` [PATCH v2 1/4] refs: expose `ref_iterator` via 'refs.h' Karthik Nayak
2025-07-04 13:02 ` [PATCH v2 2/4] ref-cache: remove unused function 'find_ref_entry()' Karthik Nayak
2025-07-04 13:02 ` [PATCH v2 3/4] refs: selectively set prefix in the seek functions Karthik Nayak
2025-07-04 13:02 ` [PATCH v2 4/4] for-each-ref: introduce a '--skip-until' option Karthik Nayak
2025-07-07 15:30 ` Junio C Hamano
2025-07-07 18:31 ` Karthik Nayak
2025-07-04 13:41 ` [PATCH v2 0/4] for-each-ref: introduce seeking functionality via '--skip-until' Andreas Schwab
2025-07-04 14:02 ` Karthik Nayak
2025-07-04 14:52 ` Andreas Schwab
2025-07-04 14:58 ` Karthik Nayak
2025-07-04 15:55 ` Andreas Schwab
2025-07-07 8:52 ` Karthik Nayak
2025-07-04 16:39 ` Junio C Hamano
2025-07-07 8:59 ` Karthik Nayak
2025-07-07 9:45 ` Phillip Wood
2025-07-08 11:39 ` Karthik Nayak
2025-07-08 13:47 ` [PATCH v3 0/4] for-each-ref: introduce seeking functionality via '--start-after' Karthik Nayak
2025-07-08 13:47 ` [PATCH v3 1/4] refs: expose `ref_iterator` via 'refs.h' Karthik Nayak
2025-07-08 13:47 ` [PATCH v3 2/4] ref-cache: remove unused function 'find_ref_entry()' Karthik Nayak
2025-07-08 13:47 ` [PATCH v3 3/4] refs: selectively set prefix in the seek functions Karthik Nayak
2025-07-10 6:44 ` Patrick Steinhardt
2025-07-11 9:44 ` Karthik Nayak
2025-07-14 16:09 ` Junio C Hamano
2025-07-15 9:49 ` Karthik Nayak
2025-07-15 16:35 ` Junio C Hamano
2025-07-16 14:40 ` Karthik Nayak
2025-07-16 15:39 ` Junio C Hamano
2025-07-16 20:02 ` Junio C Hamano
2025-07-17 9:01 ` Karthik Nayak
2025-07-17 17:31 ` Junio C Hamano
2025-07-08 13:47 ` [PATCH v3 4/4] for-each-ref: introduce a '--start-after' option Karthik Nayak
2025-07-08 20:25 ` Junio C Hamano
2025-07-09 9:53 ` Karthik Nayak
2025-07-11 16:18 ` [PATCH v4 0/4] for-each-ref: introduce seeking functionality via '--start-after' Karthik Nayak
2025-07-11 16:18 ` [PATCH v4 1/4] refs: expose `ref_iterator` via 'refs.h' Karthik Nayak
2025-07-11 16:18 ` [PATCH v4 2/4] ref-cache: remove unused function 'find_ref_entry()' Karthik Nayak
2025-07-11 16:18 ` [PATCH v4 3/4] refs: selectively set prefix in the seek functions Karthik Nayak
2025-07-14 10:34 ` Christian Couder
2025-07-15 8:19 ` Karthik Nayak
2025-07-11 16:18 ` [PATCH v4 4/4] for-each-ref: introduce a '--start-after' option Karthik Nayak
2025-07-14 16:04 ` Christian Couder
2025-07-14 16:42 ` Junio C Hamano
2025-07-15 8:42 ` Karthik Nayak
2025-07-14 16:34 ` [PATCH v4 0/4] for-each-ref: introduce seeking functionality via '--start-after' Christian Couder
2025-07-14 16:49 ` Junio C Hamano
2025-07-15 9:49 ` Karthik Nayak
2025-07-15 11:28 ` [PATCH v5 0/5] " Karthik Nayak
2025-07-15 11:28 ` [PATCH v5 1/5] refs: expose `ref_iterator` via 'refs.h' Karthik Nayak
2025-07-15 11:28 ` [PATCH v5 2/5] ref-cache: remove unused function 'find_ref_entry()' Karthik Nayak
2025-07-17 14:48 ` Junio C Hamano
2025-07-17 19:31 ` Karthik Nayak
2025-07-17 20:32 ` Junio C Hamano
2025-07-15 11:28 ` [PATCH v5 3/5] refs: selectively set prefix in the seek functions Karthik Nayak
2025-07-17 2:09 ` Jeff King
2025-07-17 19:49 ` Karthik Nayak
2025-07-17 21:55 ` Jeff King
2025-07-15 11:28 ` [PATCH v5 4/5] ref-filter: remove unnecessary else clause Karthik Nayak
2025-07-15 11:28 ` [PATCH v5 5/5] for-each-ref: introduce a '--start-after' option Karthik Nayak
2025-07-17 15:31 ` Junio C Hamano [this message]
2025-07-22 8:07 ` Karthik Nayak
2025-07-15 19:00 ` [PATCH v5 0/5] for-each-ref: introduce seeking functionality via '--start-after' Junio C Hamano
2025-07-17 1:19 ` Kyle Lippincott
2025-07-17 1:54 ` Jeff King
2025-07-17 17:08 ` Kyle Lippincott
2025-07-17 19:26 ` Karthik Nayak
2025-07-17 19:35 ` Kyle Lippincott
2025-07-17 22:09 ` Jeff King
2025-07-17 22:16 ` Jeff King
2025-07-21 14:27 ` Karthik Nayak
2025-07-21 21:22 ` Jeff King
2025-07-22 8:44 ` Karthik Nayak
2025-07-17 22:21 ` Junio C Hamano
2025-07-23 21:51 ` [PATCH] ref-iterator-seek: correctly initialize the prefix_state for a new level Junio C Hamano
2025-07-23 21:57 ` Kyle Lippincott
2025-07-23 23:52 ` Jeff King
2025-07-24 8:12 ` Karthik Nayak
2025-07-24 17:01 ` Junio C Hamano
2025-07-24 22:11 ` [PATCH] ref-cache: set prefix_state when seeking Karthik Nayak
2025-07-24 22:30 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqikjq7s16.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=phillip.wood123@gmail.com \
--cc=ps@pks.im \
--cc=schwab@linux-m68k.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).