From: Jon Simons <jon@jonsimons.org>
To: git@vger.kernel.org
Cc: Jon Simons <jon@jonsimons.org>
Subject: [PATCH 14/15] remote: restructure apply_push_cas() loops
Date: Fri, 9 Oct 2026 15:29:52 -0400 [thread overview]
Message-ID: <20261009192953.81794-15-jon@jonsimons.org> (raw)
In-Reply-To: <20261009192953.81794-1-jon@jonsimons.org>
Restructure the apply_push_cas() loops to prepare for replacing
a linear remote_refs traversal with a strmap lookup.
Before this change, apply_push_cas() loops:
for each advertised remote ref,
apply_cas(ref):
for each explicit lease entry until first match,
refname_match(entry, ref)
else if use_tracking_for_rest,
stamp from tracking
After this change the loops are inverted and apply_cas() is split
into apply_one_cas() (one explicit entry, stamp every matching
still-free ref) and apply_cas_tracking() (shared by the explicit
use_tracking path and use_tracking_for_rest):
for each explicit lease entry,
apply_one_cas(entry):
for each advertised remote ref not yet stamped,
refname_match(entry, ref)
if use_tracking_for_rest,
apply_cas_tracking() on remaining refs
In the next commit, apply_one_cas() is updated to use a strmap.
Signed-off-by: Jon Simons <jon@jonsimons.org>
---
remote.c | 66 ++++++++++++++++++++++++++++++++------------------------
1 file changed, 38 insertions(+), 28 deletions(-)
diff --git a/remote.c b/remote.c
index 8074750601..8dd163038d 100644
--- a/remote.c
+++ b/remote.c
@@ -2978,33 +2978,10 @@ static void check_if_includes_upstream(struct ref *remote)
free_one_ref(local);
}
-static void apply_cas(struct push_cas_option *cas,
- struct remote *remote,
- struct ref *ref)
+static void apply_cas_tracking(struct push_cas_option *cas,
+ struct remote *remote,
+ struct ref *ref)
{
- int i;
-
- /* Find an explicit --<option>=<name>[:<value>] entry */
- for (i = 0; i < cas->nr; i++) {
- struct push_cas *entry = &cas->entry[i];
- if (!refname_match(entry->refname, ref->name))
- continue;
- ref->expect_old_sha1 = 1;
- if (!entry->use_tracking)
- oidcpy(&ref->old_oid_expect, &entry->expect);
- else if (remote_tracking(remote, ref->name,
- &ref->old_oid_expect,
- &ref->tracking_ref))
- oidclr(&ref->old_oid_expect, the_repository->hash_algo);
- else
- ref->check_reachable = cas->use_force_if_includes;
- return;
- }
-
- /* Are we using "--<option>" to cover all? */
- if (!cas->use_tracking_for_rest)
- return;
-
ref->expect_old_sha1 = 1;
if (remote_tracking(remote, ref->name,
&ref->old_oid_expect,
@@ -3014,14 +2991,47 @@ static void apply_cas(struct push_cas_option *cas,
ref->check_reachable = cas->use_force_if_includes;
}
+static void apply_one_cas(struct ref *remote_refs,
+ struct remote *remote,
+ struct push_cas_option *cas,
+ struct push_cas *entry)
+{
+ struct ref *ref;
+
+ for (ref = remote_refs; ref; ref = ref->next) {
+ if (ref->expect_old_sha1)
+ continue;
+ if (!refname_match(entry->refname, ref->name))
+ continue;
+ if (entry->use_tracking) {
+ apply_cas_tracking(cas, remote, ref);
+ } else {
+ ref->expect_old_sha1 = 1;
+ oidcpy(&ref->old_oid_expect, &entry->expect);
+ }
+ }
+}
+
void apply_push_cas(struct push_cas_option *cas,
struct remote *remote,
struct ref *remote_refs)
{
struct ref *ref;
- for (ref = remote_refs; ref; ref = ref->next) {
- apply_cas(cas, remote, ref);
+ /* Apply each explicit --<option>=<name>[:<value>] entry */
+ for (size_t i = 0; i < cas->nr; i++)
+ apply_one_cas(remote_refs, remote, cas, &cas->entry[i]);
+
+ /* Are we using "--<option>" to cover all? */
+ if (cas->use_tracking_for_rest) {
+ for (ref = remote_refs; ref; ref = ref->next) {
+ if (ref->expect_old_sha1)
+ continue;
+ apply_cas_tracking(cas, remote, ref);
+ }
+ }
+
+ for (ref = remote_refs; ref; ref = ref->next) {
/*
* If "compare-and-swap" is in "use_tracking[_for_rest]"
* mode, and if "--force-if-includes" was specified, run
--
2.55.0
next prev parent reply other threads:[~2026-10-09 19:37 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 19:29 [PATCH 00/15] push: speed up client-side refspec matching Jon Simons
2026-10-09 19:29 ` [PATCH 01/15] remote: validate --force-with-lease <refname> argument Jon Simons
2026-10-09 19:29 ` [PATCH 02/15] t5516: demonstrate push with "./"-prefixed source Jon Simons
2026-10-09 19:29 ` [PATCH 03/15] t5510: document fetch with "./"-prefixed branch.<name>.merge Jon Simons
2026-10-09 19:29 ` [PATCH 04/15] t/perf: add explicit delete refspec matching test Jon Simons
2026-10-09 19:29 ` [PATCH 05/15] refs: stop using mkpath() in refname_match() Jon Simons
2026-10-09 19:29 ` [PATCH 06/15] remote: use strmap for check_push_refs() Jon Simons
2026-10-09 19:29 ` [PATCH 07/15] t5516: test pushing two refspecs creating the same new branch Jon Simons
2026-10-09 19:29 ` [PATCH 08/15] t5408, t5410: test duplicate updates without relying on the client Jon Simons
2026-10-09 19:29 ` [PATCH 09/15] t5408: check refspec order with distinct destinations Jon Simons
2026-10-09 19:29 ` [PATCH 10/15] t5408: expect client-side error for duplicate destinations Jon Simons
2026-10-09 19:29 ` [PATCH 11/15] remote: reject duplicate destinations on an empty remote Jon Simons
2026-10-09 19:29 ` [PATCH 12/15] remote: use strmap for match_explicit_refs() Jon Simons
2026-10-09 19:29 ` [PATCH 13/15] t/perf: measure --force-with-lease in p5516 Jon Simons
2026-10-09 19:29 ` Jon Simons [this message]
2026-10-09 19:29 ` [PATCH 15/15] remote: use strmap for apply_push_cas() Jon Simons
2026-10-09 20:18 ` [PATCH 00/15] push: speed up client-side refspec matching Kristoffer Haugsbakk
2026-10-11 2:35 ` Jon Simons
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=20261009192953.81794-15-jon@jonsimons.org \
--to=jon@jonsimons.org \
--cc=git@vger.kernel.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