From: Ben Knoble <ben.knoble@gmail.com>
To: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Cc: git@vger.kernel.org, coygeek@gmail.com, gitster@pobox.com,
r.siddharth.shrimali@gmail.com
Subject: Re: [PATCH v2] repack: do not rebuild packs on --dry-run
Date: Sat, 10 Oct 2026 17:06:18 -0400 [thread overview]
Message-ID: <BBCEC2F7-CA8A-4460-8A4F-D8305D3E9134@gmail.com> (raw)
In-Reply-To: <20261010210050.76064-1-r.siddharth.shrimali@gmail.com>
> Le 10 oct. 2026 à 17:01, Siddharth Shrimali <r.siddharth.shrimali@gmail.com> a écrit :
>
> "git repack --drop-filtered --dry-run" is documented to list the
> objects that would be dropped "without rebuilding any pack or
> deleting anything", but it does both.
>
> This is a bug in cmd_repack(): after printing the candidates, the
> --dry-run block falls through into the regular repack code.
> repack_promisor_objects() writes a new promisor pack, and with -d,
> existing_packs_remove_redundant() deletes the old packs.
>
> The existing guard only skips the implied "delete_redundant = 1", so
> it does not stop an explicit -d, and it does not stop the new pack
> from being written either.
>
> This has been broken since --dry-run was introduced in 1e746b00aa
> (builtin/repack: add --drop-filtered and --dry-run options). The
> --dry-run block never returned early, so a dry run has always gone
> on to do a regular repack. It was not broken by a later change.
>
> Fix it by returning right after the candidates are listed, and add a
> test that checks the pack directory is unchanged with and without -d.
>
> Reported-by: Coy Geek <coygeek@gmail.com>
> Helped-by: D. Ben Knoble <ben.knoble@gmail.com>
> Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
> ---
> Bug report:
> https://lore.kernel.org/git/CACgTecOm+=vbf50tZNXhcYvRi1ZTsQwbjVoJAbQqs2CmXdJCxg@mail.gmail.com/
>
> Changes since v1:
> - reworded the comment
> - documented the bug in the log message
Thanks, I’m happy with this version. You may add my Reviewed-by, if you like
> builtin/repack.c | 7 +++++++
> t/t7706-repack-drop-filtered.sh | 19 +++++++++++++++++++
> 2 files changed, 26 insertions(+)
>
> diff --git a/builtin/repack.c b/builtin/repack.c
> index c4360382c1..7797972642 100644
> --- a/builtin/repack.c
> +++ b/builtin/repack.c
> @@ -387,14 +387,21 @@ int cmd_repack(int argc,
> if (dry_run) {
> struct oidset_iter iter;
> const struct object_id *oid;
>
> oidset_iter_init(&drop_oids, &iter);
> while ((oid = oidset_iter_next(&iter)))
> printf("%s\n", oid_to_hex(oid));
> +
> + /*
> + * Only list the candidates to be dropped; skip
> + * the actual repack
> + */
> + ret = 0;
> + goto cleanup;
> }
> }
>
> if (delete_redundant && repo->repository_format_precious_objects)
> die(_("cannot delete packs in a precious-objects repo"));
>
> die_for_incompatible_opt3(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE), "-A",
> diff --git a/t/t7706-repack-drop-filtered.sh b/t/t7706-repack-drop-filtered.sh
> index cb36115834..a1c475e4ec 100755
> --- a/t/t7706-repack-drop-filtered.sh
> +++ b/t/t7706-repack-drop-filtered.sh
> @@ -131,14 +131,33 @@ test_expect_success '--dry-run does not remove the filtered objects' '
> git -C repo -c repack.writeBitmaps=false \
> repack --drop-filtered --filter=blob:limit=1k --dry-run -a >out &&
>
> # Candidate blob must still be present after a dry run.
> git -C repo cat-file -e "$BIG"
> '
>
> +test_expect_success '--dry-run leaves the pack directory untouched' '
> + BIG=$(cat big_oid) &&
> + packdir=repo/.git/objects/pack &&
> +
> + for opt in "" -d
> + do
> + ls $packdir >before &&
> +
> + git -C repo -c repack.writeBitmaps=false \
> + repack --drop-filtered --filter=blob:limit=1k \
> + --dry-run -a $opt >out &&
> +
> + ls $packdir >after &&
> + test_cmp before after &&
> + test_grep "$BIG" out &&
> + git -C repo cat-file -e "$BIG" || return 1
> + done
> +'
> +
> test_expect_success '--drop-filtered removes the promisor blob locally' '
> BIG=$(cat big_oid) &&
> SMALL=$(cat small_oid) &&
>
> git -C repo -c repack.writeBitmaps=false \
> repack --drop-filtered --filter=blob:limit=1k -a &&
>
> --
> 2.56.0
>
next prev parent reply other threads:[~2026-10-10 21:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 6:25 [PATCH] repack: do not rebuild packs on --dry-run Siddharth Shrimali
2026-10-08 12:56 ` D. Ben Knoble
2026-10-10 19:53 ` Siddharth Shrimali
2026-10-08 14:23 ` Junio C Hamano
2026-10-10 20:05 ` Siddharth Shrimali
2026-10-10 21:00 ` [PATCH v2] " Siddharth Shrimali
2026-10-10 21:06 ` Ben Knoble [this message]
2026-10-11 5:57 ` Junio C Hamano
2026-10-13 11:30 ` 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=BBCEC2F7-CA8A-4460-8A4F-D8305D3E9134@gmail.com \
--to=ben.knoble@gmail.com \
--cc=coygeek@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=r.siddharth.shrimali@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