🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #269

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

#269
From: Siddharth Shrimali
Date: Sat, 10 Oct 2026 21:00
103 lines
11416 bytes
"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

 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
Technical Details
Message-ID: <20261010210050.76064-1-r.siddharth.shrimali@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-71691-linux-kernel-git=dewy.ru
References: <20261008062521.25505-1-r.siddharth.shrimali@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-71691-linux-kernel-git=dewy.ru
From: r.siddharth.shrimali@gmail.com (Siddharth Shrimali)
Newsgroups: linux.kernel.git
Subject: [PATCH v2] repack: do not rebuild packs on --dry-run
Date: Sun, 11 Oct 2026 02:30:50 +0530
Organization: Usenet Network
Message-ID: <20261010210050.76064-1-r.siddharth.shrimali@gmail.com>
References: <20261008062521.25505-1-r.siddharth.shrimali@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1409737"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:lKmasuzfnRg2GRvxFI50pExaTms= sha256:ROF8mPg+U1T5Wz31FEKCz5md2gOAnLDMXvi0ydOepec=
	sha1:0l75M2gWYU3ApLEbXtoA5eoqO70= sha256:0LwALrTPeWe9axfckxx9R1L6SWy35OJpOIYGBHJvpXY=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id BBE8E10F94F; Sun, 11 Oct 2026 00:01:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.148
X-Spam-Status: No, score=-3.148 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id bvjqd6pEEQVV;
	Sun, 11 Oct 2026 00:01:21 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-71691-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 8810F10F8DA; Sun, 11 Oct 2026 00:01:14 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by sto.lore.kernel.org (Postfix) with ESMTP id DA3F5606CA5; Sat, 10 Oct 2026 21:01:13 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 34E29345EB5;
	Sat, 10 Oct 2026 21:01:12 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ASEN/Z8b"
X-Received: from mail-dl1-f47.google.com (mail-dl1-f47.google.com [74.125.82.47])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F665255E43
	for <git@vger.kernel.org>; Sat, 10 Oct 2026 21:01:09 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.47
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1791666071; cv=none; b=O1PF2w/P/yTzUyb2RiRwpsDD40ngDqu7MKXwM3qitxqhIbpogplqg3ul+4tsdup6o3II15fqDkrcZY38bO4RchU5JFMUEfRaya5bgDK5+uB/X4h2o79n2oGv49Y5sNcr5xYhmN6wF6mmtF92yinlvV4dCEliB/FMsWDCfKAmluo=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1791666071; c=relaxed/simple;
	bh=0XiPXt0IerbUVvHpi5pTWBRYAhotUJFa34EpXUKAhmE=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version; b=RIVjgynNewJ1X9Q9AZYcblUihTdbtBIcRXmOANaymuXN2W3ZUfeymgDJoibAADd0T4LyXk64/OyLV7qXqI6nZXsAJKR6nacikhLsWo4obXuicHR3bYa4Hklx4LvSa2z7kJdakgm4wtmcUwYdabwY7734nqCbmlmd3GReceuae5k=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ASEN/Z8b; arc=none smtp.client-ip=74.125.82.47
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dl1-f47.google.com with SMTP id a92af1059eb24-170135e43c7so280790c88.0
        for <git@vger.kernel.org>; Sat, 10 Oct 2026 14:01:09 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1791666069; x=1792270869; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=R13NhmTInGEARGt42xNwnobQtW2t9IzJDN//37fWDco=;
        b=ASEN/Z8bQtpkOvsTj1GgKmwJ2YG3yjisDZ1CGZqnmVk/FkWC07edtzVleeFo1VwTNZ
         w93rdDHq/Y1tfDXlNO83EXuqmyQfLdtCI2XNcArDURbHpb4glvwdeMKhxAY+uJY5MDeP
         S2i/jirlDPrYsp0ViGS+7iHhCFW/6UzL1PaIkBuJs5vXlCaDzLHuWR0D/gtTFBP/hmc1
         Tb4gckTZyQYUfZvNa9Gp3x6Rx5fXe7CgrC/UoLdxE9OcJlRItXop5P938Hp68jKkjVtM
         T7hpGhtwqtwpJ7iYP2FZaypB3t8DyLpizQLWo5pudZcbeoLAAH2iRsL7mXFiymoRhbR8
         PIAg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1791666069; x=1792270869;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to:content-type;
        bh=R13NhmTInGEARGt42xNwnobQtW2t9IzJDN//37fWDco=;
        b=dOwa+XEOL9nxniwvgFMlOYRyoVgD1hIy7kBQOJUkvopNDCAv9K52BIf3Nu0ZQrEdQL
         IEds5a+uUyIyi/IlBafURE+dRYWxHy/RdK1iWtSa7Fo5dtdDd0X5SpiJeeRXKDTuti/u
         6CZSmgv8JcKBxG1KqKAilLv9VaT41KG6/l8Mw8QrRom9MLwvJDxqdB+FIsfAFTUtFJba
         Stdhf5boMgyitx4Ya59JbKEwjo7TGNIYPVLc3U4O42FhH3Kd16mlQy40FpB6H3N2UCi7
         504pYq0sAUj3G+tG+dOcRdRwXK3oickZ/B+dI+gp0AUud9WFPfqDXkTDhX2qO9YKi8Zt
         SzYQ==
X-Gm-Message-State: AFq9FYLfUucHYC4wtfXGvZucspHWJDoK7v74EdcKv1D+hnjcVdsu5lyk
	yHVCJBDolfHN6ALXH2s579IBy6J4QL18AztKJBmPzcTr1hbSvn599A+7yNK4WrkA
X-Gm-Gg: AYBFou2AAvH0scCwG9zwOkiE9GO15siPLYVezaxgprqVE+QAE0hJpFib2myQfgu0bwL
	VXkCnjPCg0hTZJTmc9patTaPVzV4C7wB6sdtmGXQGg5O4BgQuO0UNCNBbI9isj7RAa7imD/oNP4
	ySVYAi/t8+xXx8QYvWe4QBarUW/53oLJk6GJqJVFMeFTQgZoEpm+CDRF3Ve4BFLBFrymDwwcHvc
	q27FLyoZ3lP6J4zN0mhg92H5W/6awid9SACE9NTy1zJFodWNkMDCrDTYiEMmBEcF8zCM8bPwjoL
	luFo4S1cnrSRKET0OWHFJj/ZvkTM5fCGzJQzVVNn/HKDeIUB4vXaoSnUPYRN2iF5gGik4RL3aG2
	t5RhJyiiQsFtmteZ/mF+Z6Nuumb6MqZ52OwyXdqT9k9SLC6uTJLev1ZI8YsOI/I7SZFI3oSAN/r
	ndU9hDKduFTOO5O2f9C7D/ALJTT/PKVz2tB6zFjVp6a0N4t9W+Zc+rmOschFUJAMJ+yQek9Wvg/
	uQ+24wKt2UHVOVYNiX35coFZP4+jxQIbWwmMbGHwLCwuQPnM10AA98nVTltfHCDL5w5icmTTzvq
	9BntOfzBuVYW7UvT8+QB37TvtCTlcCU=
X-Received: by 2002:a05:7022:e27:b0:171:a066:938e with SMTP id a92af1059eb24-171a0669487mr567128c88.21.1791666068747;
        Sat, 10 Oct 2026 14:01:08 -0700 (PDT)
X-Received: from localhost.localdomain ([2409:40c2:5436:d246:945e:7001:dd65:6221])
        by smtp.gmail.com with ESMTPSA id a92af1059eb24-169a3f6186fsm16957223c88.14.2026.10.10.14.01.05
        (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
        Sat, 10 Oct 2026 14:01:08 -0700 (PDT)
X-Cc: coygeek@gmail.com,
	ben.knoble@gmail.com,
	gitster@pobox.com,
	r.siddharth.shrimali@gmail.com
X-Mailer: git-send-email 2.56.0
X-In-Reply-To: <20261008062521.25505-1-r.siddharth.shrimali@gmail.com>
X-Precedence: bulk
X-Mailing-List: git@vger.kernel.org
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>