From: Marc Strapetz via GitGitGadget Date: Mon, 26 Oct 2026 15:46:05 GMT Subject: [PATCH 3/3] send-pack: avoid resending unchanged blobs after rebasing Message-ID: In-Reply-To: From: Marc Strapetz 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 --- 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