From: "Marc Strapetz via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Marc Strapetz <marc.strapetz@syntevo.com>,
Marc Strapetz <marc.strapetz@syntevo.com>
Subject: [PATCH 3/3] send-pack: avoid resending unchanged blobs after rebasing
Date: Mon, 26 Oct 2026 15:46:05 +0000 [thread overview]
Message-ID: <e13f12640853643e14288107ee03f99fc00bb0f1.1793029565.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2281.git.1793029565.gitgitgadget@gmail.com>
From: Marc Strapetz <marc.strapetz@syntevo.com>
Rebasing a pushed branch can put its old tip outside the boundary
traversed by pack-objects. Even with that tip among the negative
revisions, unchanged blobs may then be sent again.
For forced non-fast-forward branch updates, pass locally available
advertised old tips as haves_to_inspect. Limit this to refs selected
for sending; leave fast-forward and rejected updates out. Restrict
the hints to branches, which name commits, and skip shallow
repositories, whose thin-pack pushes already inspect negative tips
with --objects-edge-aggressive.
Update the rebase tests to expect two packed objects instead of
three: the rebased commit and its tree. The unchanged blob is
already present on the receiver.
Assisted-by: GPT-6 Astra, GPT-6.1 Sol
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
---
send-pack.c | 30 ++++++++++++++++++++++++------
t/t5516-fetch-push.sh | 2 +-
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/send-pack.c b/send-pack.c
index f20460fbf4..de6d33cf75 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -42,17 +42,18 @@ int option_parse_push_signed(const struct option *opt,
die("bad %s argument: %s", opt->long_name, arg);
}
-static void append_negative_object(struct repository *r,
- struct oid_array *haves,
- const struct object_id *oid)
+static int append_negative_object(struct repository *r,
+ struct oid_array *haves,
+ const struct object_id *oid)
{
/*
* The remote end may have advertised objects that we do not have in
* our object database. Skip those, as we cannot use them as boundary.
*/
if (!odb_has_object(r->objects, oid, 0))
- return;
+ return 0;
oid_array_append(haves, oid);
+ return 1;
}
/*
@@ -89,8 +90,25 @@ static int pack_objects(struct repository *r,
append_negative_object(r, &opts.haves, &negotiated->oid[i]);
while (refs) {
- if (!is_null_oid(&refs->old_oid))
- append_negative_object(r, &opts.haves, &refs->old_oid);
+ if (!is_null_oid(&refs->old_oid)) {
+ int added = append_negative_object(r, &opts.haves,
+ &refs->old_oid);
+
+ /*
+ * For forced pushes, inspect the old tip's tree to
+ * avoid sending objects the receiver already has.
+ * Shallow thin-pack pushes already inspect negative
+ * tips via --objects-edge-aggressive. Limit this
+ * optimization to branches because --inspect-have
+ * requires commits, while other refs may legitimately
+ * point to trees or blobs.
+ */
+ if (added && refs->forced_update && !opts.shallow &&
+ starts_with(refs->name, "refs/heads/") &&
+ (refs->status == REF_STATUS_OK ||
+ refs->status == REF_STATUS_EXPECTING_REPORT))
+ oid_array_append(&opts.haves_to_inspect, &refs->old_oid);
+ }
if (!is_null_oid(&refs->new_oid))
oid_array_append(&opts.wants, &refs->new_oid);
refs = refs->next;
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index a46ba91ba0..067b4ddc16 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -216,7 +216,7 @@ do
GIT_TRACE2_EVENT="$D/rebased-push-event" \
git -c push.useBitmaps=false push $push_args
) &&
- grep_wrote 3 rebased-push-event # 1 commit, 1 tree, 1 blob
+ grep_wrote 2 rebased-push-event # 1 commit, 1 tree
'
done
--
gitgitgadget
next prev parent reply other threads:[~2026-10-26 15:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 15:46 [PATCH 0/3] send-pack: avoid resending unchanged objects after rebasing Marc Strapetz via GitGitGadget
2026-10-26 15:46 ` [PATCH 1/3] t5516: record redundant blobs " Marc Strapetz via GitGitGadget
2026-10-26 15:46 ` [PATCH 2/3] pack-objects: inspect selected haves for shared objects Marc Strapetz via GitGitGadget
2026-10-26 15:46 ` Marc Strapetz via GitGitGadget [this message]
2026-10-26 17:26 ` [PATCH 0/3] send-pack: avoid resending unchanged objects after rebasing Junio C Hamano
2026-10-26 21:23 ` Marc Strapetz
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=e13f12640853643e14288107ee03f99fc00bb0f1.1793029565.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=marc.strapetz@syntevo.com \
/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