git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] send-pack: avoid resending unchanged blobs after rebasing

From
Marc Strapetz via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 26, 2026, 15:46 UTC
Message-ID
<e13f12640853643e14288107ee03f99fc00bb0f1.1793029565.git.gitgitgadget@gmail.com>
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
Previous: Marc Strapetz via GitGitGadgetNext: Junio C Hamano
Message 4 of 7 in “send-pack: avoid resending unchanged objects after rebasing”
  1. 0/3 send-pack: avoid resending unchanged objects after rebasingMarc Strapetz via GitGitGadget, Oct 26, 2026
  2. 1/3 t5516: record redundant blobs after rebasingMarc Strapetz via GitGitGadget, Oct 26, 2026
  3. 2/3 pack-objects: inspect selected haves for shared objectsMarc Strapetz via GitGitGadget, Oct 26, 2026
  4. 3/3 send-pack: avoid resending unchanged blobs after rebasingMarc Strapetz via GitGitGadget, Oct 26, 2026
  5. Junio C HamanoOct 26, 2026
  6. Marc StrapetzOct 26, 2026
  7. Marc StrapetzNov 4, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.