]> git.ipfire.org Git - thirdparty/git.git/commitdiff
send-pack: honor `no-ref-delta` capability
authorTaylor Blau <ttaylorr@openai.com>
Mon, 13 Jul 2026 01:12:07 +0000 (18:12 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Jul 2026 01:39:03 +0000 (18:39 -0700)
Add a 'no-ref-delta' receive-pack capability and teach send-pack to pass
'--no-ref-delta' to 'pack-objects' when the server advertises it.

Keep this separate from 'ofs-delta' so that a server may request that
`send-pack` omit `REF_DELTA` without also accepting `OFS_DELTA`.

Signed-off-by: Taylor Blau <ttaylorr@openai.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/gitprotocol-capabilities.adoc
builtin/receive-pack.c
send-pack.c
send-pack.h
t/t5516-fetch-push.sh

index 2cf7735be479e6863f4e373bd7cf7794624e0094..bbe88defdff1d8075daf81ab4ee58b12527520fe 100644 (file)
@@ -34,9 +34,9 @@ were sent.  Server MUST NOT ignore capabilities that client requested
 and server advertised.  As a consequence of these rules, server MUST
 NOT advertise capabilities it does not understand.
 
-The 'atomic', 'report-status', 'report-status-v2', 'delete-refs', 'quiet',
-and 'push-cert' capabilities are sent and recognized by the receive-pack
-(push to server) process.
+The 'atomic', 'report-status', 'report-status-v2', 'delete-refs',
+'no-ref-delta', 'quiet', and 'push-cert' capabilities are sent and
+recognized by the receive-pack (push to server) process.
 
 The 'ofs-delta' and 'side-band-64k' capabilities are sent and recognized
 by both upload-pack and receive-pack protocols.  The 'agent' and 'session-id'
@@ -174,6 +174,17 @@ The server can send, and the client can understand, PACKv2 with delta referring
 its base by position in pack rather than by an obj-id.  That is, they can
 send/read OBJ_OFS_DELTA (aka type 6) in a packfile.
 
+no-ref-delta
+------------
+
+The receive-pack server can request, and the client can send, PACKv2
+without deltas referring to their bases by an obj-id. That is, the
+client MUST NOT send OBJ_REF_DELTA (aka type 7) in a packfile when the
+server advertises this capability.
+
+This does not imply that the server understands OBJ_OFS_DELTA entries;
+that is negotiated separately with the 'ofs-delta' capability.
+
 agent
 -----
 
index 19eb6a1b61c3a73f9d87d54ff075b1fb12a0b5e3..1c516cbdc64efb023ab07c85798c9684cfba4b86 100644 (file)
@@ -66,6 +66,7 @@ static struct strbuf fsck_msg_types = STRBUF_INIT;
 static int receive_unpack_limit = -1;
 static int transfer_unpack_limit = -1;
 static int advertise_atomic_push = 1;
+static int advertise_no_ref_delta;
 static int advertise_push_options;
 static int advertise_sid;
 static int unpack_limit = 100;
@@ -290,6 +291,8 @@ static void show_ref(const char *path, const struct object_id *oid)
                        strbuf_addstr(&cap, " atomic");
                if (prefer_ofs_delta)
                        strbuf_addstr(&cap, " ofs-delta");
+               if (advertise_no_ref_delta)
+                       strbuf_addstr(&cap, " no-ref-delta");
                if (push_cert_nonce)
                        strbuf_addf(&cap, " push-cert=%s", push_cert_nonce);
                if (advertise_push_options)
@@ -2631,6 +2634,8 @@ int cmd_receive_pack(int argc,
                OPT_HIDDEN_BOOL(0, "http-backend-info-refs", &advertise_refs, NULL),
                OPT_ALIAS(0, "advertise-refs", "http-backend-info-refs"),
                OPT_HIDDEN_BOOL(0, "reject-thin-pack-for-testing", &reject_thin, NULL),
+               OPT_HIDDEN_BOOL(0, "advertise-no-ref-delta-for-testing",
+                               &advertise_no_ref_delta, NULL),
                OPT_END()
        };
 
index 3bb5afc687aaf02481713de98ac677ec821fb122..2beb1c4be9624fa0b2b5d5c579001ee7bd6dad9c 100644 (file)
@@ -80,6 +80,8 @@ static int pack_objects(struct repository *r,
                strvec_push(&po.args, "--thin");
        if (args->use_ofs_delta)
                strvec_push(&po.args, "--delta-base-offset");
+       if (args->no_ref_delta)
+               strvec_push(&po.args, "--no-ref-delta");
        if (args->quiet || !args->progress)
                strvec_push(&po.args, "-q");
        if (args->progress)
@@ -570,6 +572,8 @@ int send_pack(struct repository *r,
                allow_deleting_refs = 1;
        if (server_supports("ofs-delta"))
                args->use_ofs_delta = 1;
+       if (server_supports("no-ref-delta"))
+               args->no_ref_delta = 1;
        if (server_supports("side-band-64k"))
                use_sideband = 1;
        if (server_supports("quiet"))
index 13850c98bb093a26e95bb3de521a3c96621cb953..30be2be0f2b8fb658f3402a189cdf5e88e4b7ca2 100644 (file)
@@ -28,6 +28,7 @@ struct send_pack_args {
                force_update:1,
                use_thin_pack:1,
                use_ofs_delta:1,
+               no_ref_delta:1,
                dry_run:1,
                /* One of the SEND_PACK_PUSH_CERT_* constants. */
                push_cert:2,
index 1b986349a86f3efd94a2a5d63233b81a67b98d4a..c00074afe88282ecf5cb4209764bce7d6e1b98c8 100755 (executable)
@@ -1548,6 +1548,20 @@ EOF
        git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/main:refs/heads/foo
 '
 
+test_expect_success 'push honors no-ref-delta capability' '
+       test_commit no-ref-delta &&
+
+       rcvpck="git receive-pack --advertise-no-ref-delta-for-testing" &&
+
+       GIT_TRACE2_EVENT="$PWD/no-ref-delta" \
+       git push --receive-pack="$rcvpck" no-thin/.git \
+               refs/heads/main:refs/heads/bar &&
+
+       test_subcommand git pack-objects --all-progress-implied --revs \
+               --stdout --thin --delta-base-offset --no-ref-delta -q \
+               <no-ref-delta
+'
+
 test_expect_success 'pushing a tag pushes the tagged object' '
        blob=$(echo unreferenced | git hash-object -w --stdin) &&
        git tag -m foo tag-of-blob $blob &&