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

[PATCH v3] repack: do not rebuild packs on --dry-run

From
Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Date
Oct 16, 2026, 19:13 UTC
Message-ID
<20261016191344.82688-1-r.siddharth.shrimali@gmail.com>
In-Reply-To
<20261010210050.76064-1-r.siddharth.shrimali@gmail.com>

"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.

A dry run can no longer get past that point, so the two "!dry_run" checks that tried to keep it from deleting or dropping anything are now redundant.

Reported-by: Coy Geek <coygeek@gmail.com>
Helped-by: D. Ben Knoble <ben.knoble@gmail.com>
Helped-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
---
Bug report:
https://lore.kernel.org/git/CACgTecOm+=vbf50tZNXhcYvRi1ZTsQwbjVoJAbQqs2CmXdJCxg@mail.gmail.com/
Changes since v2:
 - dropped the "!dry_run" checks around the implied -d and the
   repack_promisor_objects() call, which the early return made
   redundant
 builtin/repack.c                | 14 ++++++++++----
 t/t7706-repack-drop-filtered.sh | 19 +++++++++++++++++++
 2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/builtin/repack.c b/builtin/repack.c
index c4360382c1..19894804f0 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -347,18 +347,17 @@ int cmd_repack(int argc,
 		}
 
 		write_bitmaps = 0;
 
 		/*
 		 * Dropping objects means rebuilding the promisor packs
 		 * without them and then removing the old packs, so the
-		 * redundant packs must be deleted. Imply -d on a real run.
+		 * redundant packs must be deleted. Imply -d.
 		 */
-		if (!dry_run)
-			delete_redundant = 1;
+		delete_redundant = 1;
 
 		ret = enumerate_promisor_blobs(repo, &po_args.filter_options, &drop_oids);
 
 		if (ret)
 			goto cleanup;
 
 		/*
@@ -387,14 +386,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",
@@ -501,15 +507,15 @@ int cmd_repack(int argc,
 			strvec_push(&cmd.args, "--write-bitmap-index-quiet");
 	}
 	if (use_delta_islands)
 		strvec_push(&cmd.args, "--delta-islands");
 
 	if (pack_everything & ALL_INTO_ONE) {
 		repack_promisor_objects(repo, &po_args, &names, packtmp,
-			(drop_filtered && !dry_run) ? &drop_oids : NULL);
+			drop_filtered ? &drop_oids : NULL);
 
 		if (existing_packs_has_non_kept(&existing) &&
 		    delete_redundant &&
 		    !(pack_everything & PACK_CRUFT)) {
 			for_each_string_list_item(item, &names) {
 				strvec_pushf(&cmd.args, "--keep-pack=%s-%s.pack",
 					     packtmp_name, item->string);
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
Previous: Siddharth ShrimaliNext: Junio C Hamano
Message 11 of 14 in “repack: do not rebuild packs on --dry-run”
  1. repack: do not rebuild packs on --dry-runSiddharth Shrimali, Oct 8, 2026
  2. D. Ben KnobleOct 8, 2026
  3. Siddharth ShrimaliOct 10, 2026
  4. Junio C HamanoOct 8, 2026
  5. Siddharth ShrimaliOct 10, 2026
  6. repack: do not rebuild packs on --dry-runSiddharth Shrimali, Oct 10, 2026
  7. Ben KnobleOct 10, 2026
  8. Junio C HamanoOct 11, 2026
  9. Patrick SteinhardtOct 13, 2026
  10. Siddharth ShrimaliOct 16, 2026
  11. repack: do not rebuild packs on --dry-runSiddharth Shrimali, Oct 16, 2026
  12. Junio C HamanoOct 16, 2026
  13. Siddharth ShrimaliOct 17, 2026
  14. Patrick SteinhardtOct 19, 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.