From: Christian Couder <christian.couder@gmail.com>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com, ps@pks.im,
schwab@linux-m68k.org, phillip.wood123@gmail.com
Subject: Re: [PATCH v4 4/4] for-each-ref: introduce a '--start-after' option
Date: Mon, 14 Jul 2025 18:04:21 +0200 [thread overview]
Message-ID: <CAP8UFD1wRxZDCRC76VuuA8_rpNn__TQnL9RnNumCE33wAjSrMQ@mail.gmail.com> (raw)
In-Reply-To: <20250711-306-git-for-each-ref-pagination-v4-4-ed3303ad5b89@gmail.com>
On Fri, Jul 11, 2025 at 6:21 PM Karthik Nayak <karthik.188@gmail.com> wrote:
> /*
> * This is the same as for_each_fullref_in(), but it tries to iterate
> * only over the patterns we'll care about. Note that it _doesn't_ do a full
> @@ -2692,10 +2710,13 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
> each_ref_fn cb,
> void *cb_data)
> {
> + struct ref_iterator *iter;
> + int flags = 0, ret = 0;
> +
> if (filter->kind & FILTER_REFS_ROOT_REFS) {
> /* In this case, we want to print all refs including root refs. */
> - return refs_for_each_include_root_refs(get_main_ref_store(the_repository),
> - cb, cb_data);
> + flags |= DO_FOR_EACH_INCLUDE_ROOT_REFS;
> + goto non_prefix_iter;
> }
>
> if (!filter->match_as_path) {
> @@ -2704,8 +2725,7 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
> * prefixes like "refs/heads/" etc. are stripped off,
> * so we have to look at everything:
> */
> - return refs_for_each_fullref_in(get_main_ref_store(the_repository),
> - "", NULL, cb, cb_data);
> + goto non_prefix_iter;
> }
>
> if (filter->ignore_case) {
> @@ -2714,20 +2734,29 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
> * so just return everything and let the caller
> * sort it out.
> */
> - return refs_for_each_fullref_in(get_main_ref_store(the_repository),
> - "", NULL, cb, cb_data);
> + goto non_prefix_iter;
> }
>
> if (!filter->name_patterns[0]) {
> /* no patterns; we have to look at everything */
> - return refs_for_each_fullref_in(get_main_ref_store(the_repository),
> - "", filter->exclude.v, cb, cb_data);
> + goto non_prefix_iter;
> }
>
> return refs_for_each_fullref_in_prefixes(get_main_ref_store(the_repository),
> NULL, filter->name_patterns,
> filter->exclude.v,
> cb, cb_data);
> +
> +non_prefix_iter:
> + iter = refs_ref_iterator_begin(get_main_ref_store(the_repository), "",
> + NULL, 0, flags);
> + if (filter->start_after)
> + ret = start_ref_iterator_after(iter, filter->start_after);
> +
> + if (ret)
> + return ret;
> +
> + return do_for_each_ref_iterator(iter, cb, cb_data);
> }
Nit: I wonder if what is under the 'non_prefix_iter' label could be in
a new function and instead of `goto non_prefix_iter` we could return
the result of the new function.
> /*
> @@ -3197,9 +3226,11 @@ static int do_filter_refs(struct ref_filter *filter, unsigned int type, each_ref
> init_contains_cache(&filter->internal.no_contains_cache);
>
> /* Simple per-ref filtering */
> - if (!filter->kind)
> + if (!filter->kind) {
> die("filter_refs: invalid type");
> - else {
> + } else {
Nit: the `else` could be removed altogether here, but maybe that
should be done in a preparatory patch.
> + const char *prefix = NULL;
> +
[...]
> +test_expect_success 'start after with specific directory and trailing slash' '
> + cat >expect <<-\EOF &&
> + refs/odd/spot
> + refs/tags/annotated-tag
> + refs/tags/doubly-annotated-tag
> + refs/tags/doubly-signed-tag
> + refs/tags/foo1.10
> + refs/tags/foo1.3
> + refs/tags/foo1.6
> + refs/tags/four
> + refs/tags/one
> + refs/tags/signed-tag
> + refs/tags/three
> + refs/tags/two
> + EOF
> + git for-each-ref --format="%(refname)" --start-after=refs/lost >actual &&
I don't see a trailing slash.
> + test_cmp expect actual
> +'
> +
> +test_expect_success 'start after, just behind a specific directory' '
> + cat >expect <<-\EOF &&
> + refs/odd/spot
> + refs/tags/annotated-tag
> + refs/tags/doubly-annotated-tag
> + refs/tags/doubly-signed-tag
> + refs/tags/foo1.10
> + refs/tags/foo1.3
> + refs/tags/foo1.6
> + refs/tags/four
> + refs/tags/one
> + refs/tags/signed-tag
> + refs/tags/three
> + refs/tags/two
> + EOF
> + git for-each-ref --format="%(refname)" --start-after=refs/odd/ >actual &&
Here there is a trailing slash though.
> + test_cmp expect actual
> +'
next prev parent reply other threads:[~2025-07-14 16:04 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 [this message]
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
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=CAP8UFD1wRxZDCRC76VuuA8_rpNn__TQnL9RnNumCE33wAjSrMQ@mail.gmail.com \
--to=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--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).