From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, peff@peff.net, Patrick Steinhardt <ps@pks.im>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Derrick Stolee <stolee@gmail.com>
Subject: [PATCH v2 0/3] Fix REF_DELTA chain bug in 'git index-pack'
Date: Mon, 28 Apr 2025 20:24:42 +0000 [thread overview]
Message-ID: <pull.1906.v2.git.1745871885.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1906.git.1745430004.gitgitgadget@gmail.com>
When fetching content from a remote, 'git index-pack' processes the packfile
content, storing a packfile appropriate for on-disk storage and a pack-index
helping to perform random-access into that packfile. To help with
compression, the packfile sent over the wire can use REF_DELTAs in addition
to OFS_DELTAs to refer to objects that are already known to exist in the
client's repository. REF_DELTAs can also refer to objects within the
packfile, though this is not typically done.
Because this inter-pack REF_DELTA is not a typical data shape, a latent bug
has been waiting that causes 'git index-pack' to die() even on legitimate
packfile content that it could resolve.
This series resolves this problem while also creating a test helper for
constructing packfiles with specific objects represented in specific types
of deltas and in a given order. This should make it easier to create test
cases like this in the future instead of updating t/lib-pack.sh through
other means.
Updates in V2
=============
* Fixed a memory leak in the test helper.
* The test helper has a better CLI that makes use of the parse-options
library.
* The test script skips the in file and instead feeds the input directly to
the test helper.
Thanks, -Stolee
Derrick Stolee (3):
test-tool: add pack-deltas helper
t5309: create failing test for 'git index-pack'
index-pack: allow revisiting REF_DELTA chains
Makefile | 1 +
builtin/index-pack.c | 58 ++++++++------
t/helper/meson.build | 1 +
t/helper/test-pack-deltas.c | 148 +++++++++++++++++++++++++++++++++++
t/helper/test-tool.c | 1 +
t/helper/test-tool.h | 1 +
t/t5309-pack-delta-cycles.sh | 34 +++++++-
7 files changed, 216 insertions(+), 28 deletions(-)
create mode 100644 t/helper/test-pack-deltas.c
base-commit: 4bbb303af69990ccd05fe3a2eb58a1ce036f8220
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1906%2Fderrickstolee%2Findex-pack-ref-deltas-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1906/derrickstolee/index-pack-ref-deltas-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1906
Range-diff vs v1:
1: 5d4beb202d6 ! 1: 41aac8e782f test-tool: add pack-deltas helper
@@ t/helper/test-pack-deltas.c (new)
+#include "hex.h"
+#include "pack.h"
+#include "pack-objects.h"
++#include "parse-options.h"
+#include "setup.h"
+#include "strbuf.h"
+#include "string-list.h"
+
-+static const char usage_str[] = "test-tool pack-deltas <n>";
++static const char *usage_str[] = {
++ "test-tool pack-deltas --num-objects <num-objects>",
++ NULL
++};
+
+static unsigned long do_compress(void **pptr, unsigned long size)
+{
@@ t/helper/test-pack-deltas.c (new)
+
+int cmd__pack_deltas(int argc, const char **argv)
+{
-+ int N;
++ int num_objects = -1;
+ struct hashfile *f;
+ struct strbuf line = STRBUF_INIT;
++ struct option options[] = {
++ OPT_INTEGER('n', "num-objects", &num_objects, N_("the number of objects to write")),
++ OPT_END()
++ };
+
-+ if (argc != 2) {
-+ usage(usage_str);
-+ return -1;
-+ }
++ argc = parse_options(argc, argv, NULL,
++ options, usage_str, 0);
+
-+ N = atoi(argv[1]);
++ if (argc || num_objects < 0)
++ usage_with_options(usage_str, options);
+
+ setup_git_directory();
+
+ f = hashfd(the_repository->hash_algo, 1, "<stdout>");
-+ write_pack_header(f, N);
++ write_pack_header(f, num_objects);
+
+ /* Read each line from stdin into 'line' */
+ while (strbuf_getline_lf(&line, stdin) != EOF) {
@@ t/helper/test-pack-deltas.c (new)
+ if (get_oid_hex(base_oid_str, &base_oid))
+ die("invalid object: %s", base_oid_str);
+ }
++ string_list_clear(&items, 0);
+
+ if (!strcmp(type_str, "REF_DELTA"))
+ write_ref_delta(f, &content_oid, &base_oid);
2: a9430447641 ! 2: 53a990e69ea t5309: create failing test for 'git index-pack'
@@ t/t5309-pack-delta-cycles.sh: test_expect_success 'failover to a duplicate objec
+ C=$(git -C server rev-parse HEAD~2^{tree}) &&
+ git -C server reset --hard HEAD~1 &&
+
-+ cat >in <<-EOF &&
++ test-tool -C server pack-deltas --num-objects=2 >thin.pack <<-EOF &&
+ REF_DELTA $A $B
+ REF_DELTA $B $C
+ EOF
+
-+ test-tool -C server pack-deltas 2 <in >thin.pack &&
-+
+ git clone "file://$(pwd)/server" client &&
+ (
+ cd client &&
3: 27d36402fe9 = 3: 1358039b2f3 index-pack: allow revisiting REF_DELTA chains
--
gitgitgadget
next prev parent reply other threads:[~2025-04-28 20:24 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-23 17:40 [PATCH 0/3] Fix REF_DELTA chain bug in 'git index-pack' Derrick Stolee via GitGitGadget
2025-04-23 17:40 ` [PATCH 1/3] test-tool: add pack-deltas helper Derrick Stolee via GitGitGadget
2025-04-23 19:26 ` Junio C Hamano
2025-04-23 19:32 ` Derrick Stolee
2025-04-24 19:41 ` Junio C Hamano
2025-04-24 20:06 ` Derrick Stolee
2025-04-24 20:56 ` Junio C Hamano
2025-04-25 4:34 ` Patrick Steinhardt
2025-04-25 9:34 ` Johannes Schindelin
2025-04-25 9:45 ` Patrick Steinhardt
2025-04-25 9:51 ` Johannes Schindelin
2025-04-25 16:27 ` Junio C Hamano
2025-04-28 15:22 ` Derrick Stolee
2025-04-28 16:37 ` Junio C Hamano
2025-04-28 18:59 ` Derrick Stolee
2025-04-28 20:35 ` Junio C Hamano
2025-04-23 17:40 ` [PATCH 2/3] t5309: create failing test for 'git index-pack' Derrick Stolee via GitGitGadget
2025-04-23 19:37 ` Junio C Hamano
2025-04-23 17:40 ` [PATCH 3/3] index-pack: allow revisiting REF_DELTA chains Derrick Stolee via GitGitGadget
2025-04-24 21:41 ` Junio C Hamano
2025-04-25 3:49 ` Derrick Stolee
2025-04-28 20:24 ` Derrick Stolee via GitGitGadget [this message]
2025-04-28 20:24 ` [PATCH v2 1/3] test-tool: add pack-deltas helper Derrick Stolee via GitGitGadget
2025-04-28 20:24 ` [PATCH v2 2/3] t5309: create failing test for 'git index-pack' Derrick Stolee via GitGitGadget
2025-04-28 20:24 ` [PATCH v2 3/3] index-pack: allow revisiting REF_DELTA chains Derrick Stolee via GitGitGadget
2025-05-07 2:08 ` Taylor Blau
2025-05-07 13:47 ` Derrick Stolee
2025-04-28 22:40 ` [PATCH v2 0/3] Fix REF_DELTA chain bug in 'git index-pack' Junio C Hamano
2025-04-29 5:33 ` Patrick Steinhardt
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=pull.1906.v2.git.1745871885.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
--cc=ps@pks.im \
--cc=stolee@gmail.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;
as well as URLs for NNTP newsgroup(s).