🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #1231

[PATCH v2 08/13] object-file: handle compatibility algorithm

#1231
From: Christian Couder
Date: Fri, 23 Oct 2026 07:25
113 lines
15054 bytes
From: "brian m. carlson" <sandals@crustytoothpaste.net>

When we check in a large blob, we stream it directly to a pack and then
write an index.  However, in compatibility mode, we also need to make
sure to compute the object ID for the compatibility algorithm as well as
the main algorithm or we will incorrectly store the null OID in the
index we create.  Do so here to avoid corrupting the repository.

Add a test that adds a large file in a repository with a compatibility
algorithm.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Christian Couder <christian.couder@gmail.com>
---
 object-file.c                 | 18 ++++++++++++++++--
 t/t1016-compatObjectFormat.sh | 14 ++++++++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/object-file.c b/object-file.c
index c049bf13f7..b4c4a2ea0f 100644
--- a/object-file.c
+++ b/object-file.c
@@ -747,6 +747,7 @@ static int hash_stream(struct odb_stream *stream,
  */
 static void stream_to_pack(struct transaction_packfile *state,
 			   struct git_hash_ctx *ctx,
+			   struct git_hash_ctx *compat_ctx,
 			   struct odb_stream *stream)
 {
 	git_zstream s;
@@ -774,6 +775,9 @@ static void stream_to_pack(struct transaction_packfile *state,
 				is_finished = true;
 
 			git_hash_update(ctx, ibuf, rsize);
+			if (compat_ctx)
+				git_hash_update(compat_ctx,
+						ibuf, rsize);
 
 			s.next_in = ibuf;
 			s.avail_in = rsize;
@@ -882,16 +886,22 @@ static int odb_transaction_files_write_object_stream(struct odb_transaction *bas
 								 struct odb_transaction_files,
 								 base);
 	struct transaction_packfile *state = &transaction->packfile;
-	struct git_hash_ctx ctx;
+	struct git_hash_ctx ctx, compat_ctx;
+	struct object_id compat_oid;
 	unsigned char obuf[16384];
 	unsigned header_len;
 	struct hashfile_checkpoint checkpoint;
 	struct pack_idx_entry *idx;
+	const struct git_hash_algo *compat = transaction->base.source->odb->repo->compat_hash_algo;
 
 	header_len = format_object_header((char *)obuf, sizeof(obuf),
 					  stream->type, stream->size);
 	git_hash_init(&ctx, transaction->base.source->odb->repo->hash_algo);
 	git_hash_update(&ctx, obuf, header_len);
+	if (compat) {
+		git_hash_init(&compat_ctx, compat);
+		git_hash_update(&compat_ctx, obuf, header_len);
+	}
 
 	/*
 	 * If writing another object to the packfile could result in it
@@ -916,8 +926,10 @@ static int odb_transaction_files_write_object_stream(struct odb_transaction *bas
 	hashfile_checkpoint(state->f, &checkpoint);
 	idx->offset = state->offset;
 	crc32_begin(state->f);
-	stream_to_pack(state, &ctx, stream);
+	stream_to_pack(state, &ctx, compat ? &compat_ctx : NULL, stream);
 	git_hash_final_oid(result_oid, &ctx);
+	if (compat)
+		git_hash_final_oid(&compat_oid, &compat_ctx);
 
 	idx->crc32 = crc32_end(state->f);
 	if (already_written(transaction, result_oid)) {
@@ -926,6 +938,8 @@ static int odb_transaction_files_write_object_stream(struct odb_transaction *bas
 		free(idx);
 	} else {
 		oidcpy(&idx->oid, result_oid);
+		if (compat)
+			oidcpy(&idx->compat_oid, &compat_oid);
 		ALLOC_GROW(state->written,
 			   state->nr_written + 1,
 			   state->alloc_written);
diff --git a/t/t1016-compatObjectFormat.sh b/t/t1016-compatObjectFormat.sh
index 1560b6a2e2..af9532aa1f 100755
--- a/t/t1016-compatObjectFormat.sh
+++ b/t/t1016-compatObjectFormat.sh
@@ -228,6 +228,20 @@ do
 		test_copy_bytes 8 <v3.idx | test-tool hexdump >actual &&
 		test_cmp expect actual
 	'
+
+	test_expect_success 'add a large file streamed into a pack' '
+		test_when_finished "rm -rf large-repo" &&
+		create_compat_repo $hash large-repo &&
+		git -C large-repo config set core.bigFileThreshold 1k &&
+		test-tool genrandom large 5000 >large-repo/large &&
+		git -C large-repo add large &&
+		ls large-repo/.git/objects/pack/pack-*.pack &&
+		git -C large-repo hash-object large >expect &&
+		git -C large-repo rev-parse :large >actual &&
+		test_cmp expect actual &&
+		git -C large-repo cat-file blob :large >actual &&
+		test_cmp large-repo/large actual
+	'
 done
 cd "$base"
 
-- 
2.56.0.215.g47fdf2208c
Technical Details
Message-ID: <20261023072559.3204273-9-christian.couder@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-72954-linux-kernel-git=dewy.ru
References: <20261023072559.3204273-1-christian.couder@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-72954-linux-kernel-git=dewy.ru
From: christian.couder@gmail.com (Christian Couder)
Newsgroups: linux.kernel.git
Subject: [PATCH v2 08/13] object-file: handle compatibility algorithm
Date: Fri, 23 Oct 2026 09:25:53 +0200
Organization: Usenet Network
Message-ID: <20261023072559.3204273-9-christian.couder@gmail.com>
References: <20261023072559.3204273-1-christian.couder@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="436963"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:IcYYqKEnd7wPdtd7GKgWk1sh1gA= sha256:GIFlTUU5fCXKGYmwY0+Al9mCFESIeFb00s1aSumMnXs=
	sha1:v/kOQL1jUJf7iU74X/crl4CqAx0= sha256:Cb/P6IuTLqXF28Ucs1TByR+Q59zpVD+WWa58IjiJ7t4=
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 A547E111416; Fri, 23 Oct 2026 10:27:41 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.047
X-Spam-Status: No, score=-2.047 tagged_above=-9999 required=6.31
	tests=[DCC_CHECK=1.1, 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.25,
	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 1vGPJyaEuNFk;
	Fri, 23 Oct 2026 10:27:39 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-72954-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 0A47C111413; Fri, 23 Oct 2026 10:27:31 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 65D0860D64C; Fri, 23 Oct 2026 07:26:39 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1792740391;
	b=kF7vZyKmSt4q+0XZXXVMWM3GViAzhmczM511edzSFX0FakAvCXihKnwgtAyci6TlQGwB
	 bjAYQWs9s94z1BgTLHFsYK9T0KkmUzsOyivsiRhReSc99/nnSMrhzPeHVmxVF/W44BXuF
	 8o/vmdJg2Lf4+zrO7arP7K6JvMNF4ssqS1wZn0htmDsqpCXUHyejsChB9PDScTJ9SD/CE
	 WBDWE4GbRd1eL8Oy8Fs90MEKV+1RzkrN8UqssgH0AnSC5XXGWj1kgyQhgmciceINNElav
	 kZvnRGHp6cXjBTCfbSidFi/nKKibSrveqYDYHwp2ibp2bBmtQ9EBI+1Or6xQMddSGKw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792740391;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
	 References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=Tgb4AU6j7Qurj1SUgtj+v7yLZdOWoKJCV79ND9yOo6g=;
	b=XwlFk/Mb4zSBmNnD3MsM7nGxhphT860Jy7mHTcBVud257MNS5u37xQWhFjdx7WWMuxuY
	 kYLlpOCVL01qarNvVkVzdpwxelR8iMDUcWC3MhbdZwG1W6lEUVm5GLhYblD5ND7MnIx4I
	 cwPqi0M6NURovOwWM5P+jCksSQczc3uosv1rIVgZVWhFLzWSl8FsZ+NgiM3F/yyi+rRML
	 3p6qBgy18zpV1/uXRb7+dQqJIDSM9eh2W2WnLnouMyp2tGS0fZibnQrdx6HQiO1ZSku+a
	 9bD/EC/nZYHH5yCBNaXVrUtkD2Wrq+pL7I8+f6kzyi+FcwJ++kClDfbMRH809JrRb8g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=oU8JNWIW;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 86F2860A2608;
	Fri, 23 Oct 2026 07:26:31 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=oU8JNWIW
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.45
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792740390;
	b=rqybpNTYh+vWu3x2GwF3GhfwKGV6to9nqgaZyPV/r34af8DWVBJJNYXkNJjN42E8IdhE
	 q6OP9pr3vBnePH2DR0YOBKsDZPUglSzED+QSRTk8/l84IhaWRTxC6VG/hqAfG1G7NQQMp
	 3izVfhgIWgSAa/F2rZ3c4tofz8ZzeLpg+FvKFz81ZeIf6DVgzv05m/RpnimFrsyWaXXRj
	 fS4Zl5Fg5sY3miHpTsx7LhIN6iNxUp69nCTZI+Yi2r+tQYBndPoYOZN/G5ObfTClW91L5
	 LM25NbojyYRWBsgtROmoFnASDkpkW5+mEsgjKa0gTGq7QSkEoWyArASLCDrGlrLUFiQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792740390;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=Tgb4AU6j7Qurj1SUgtj+v7yLZdOWoKJCV79ND9yOo6g=;
	b=WS4yTATPh+pcK2uRh7b7iGBB20Va+ZhtrqrBDrxRVJROhaw8vNmUUeA+xJVrFzfxkIGG
	 f/D4uAIZBmCP8HryIrZt0pgfwfYxCsEQuCwOXLOp0xunjGZwBJWFMxBMhMUpCPqr13PzY
	 /WfldVj/73OH3VB8kdzBaiGByiDKFcutZjDoLOXULfP3Nj45srBzyVSKdP6z+3iWnOWmq
	 wPmgQDB9iO3j5fN3BzHfKeMiJgrPbbMyKZe1RN6CuvzSiI9UeE0zMPUy5lA6f6EoOoOzo
	 Cl5et/NdQQyUcnVLkAxAhGOyxwvN7Fmc2dwl2zmd4lgD/WOhT3Lt9bZXi7EfME4RprQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=oU8JNWIW;
	arc=none smtp.remote-ip=209.85.221.45
X-Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58A2E606A334
	for <git@vger.kernel.org>; Fri, 23 Oct 2026 07:26:30 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 58A2E606A334
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-wr1-f45.google.com with SMTP id ffacd0b85a97d-48df4f540ebso286937f8f.3
        for <git@vger.kernel.org>; Fri, 23 Oct 2026 00:26:30 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1792740389; x=1793345189; 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=Tgb4AU6j7Qurj1SUgtj+v7yLZdOWoKJCV79ND9yOo6g=;
        b=oU8JNWIWXB5uOvDaMx7vYjzcGvbQOSzRBWiKdRgpElR/jBUva/4JCoA3CjnfAvahwr
         rPW0ilIbHvTnNfXJpl4kwUg5WSbEC8WdYhEeMvrmYzwT3h4Ck749/Bwe+it4ECCIZNiz
         gFzon/pZqwQVEJXrwq+p9gFMM7FlCbvflw8skx6ASeszvE6mgADYVerzcQgFSt4qya0w
         OZBxwjdVf6XmFAmtE4AKHpsPlDdIR8HDJ2ZkRp2QQQau8Hu1JAxzru2wzXinxTxRI+8e
         /zlU5ZAvonR3DrfO5n/SPbijr8F98YhBZ8Is8ibM4PTziN/RaDrOKlIOkAwGWIc8qWvy
         zPhg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1792740389; x=1793345189;
        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=Tgb4AU6j7Qurj1SUgtj+v7yLZdOWoKJCV79ND9yOo6g=;
        b=szX2TTAF9mZCiU82lUhWVmJetlDiKm/oYKidHUzM9i7SWdrlvfIRFp0xTS1b7+P8Pu
         hUECOKrLv3AYNmD+mbWqlKIPKle4IcqEtKXnnQuNMJ0uMIuQfp03IXSLYmcsdVbTcTY2
         WRpCTxtEEZRKGlBPdL4MWBXcpyRfB4N38sCBU9P4DPQvIDWX6B8CfpuZCEvn6ZFWEeAH
         O8z29fT4HlrpMcy1tN/kJJ3hifa80avNunUNPgBkCnfC5q1oGQFH6nNPhd9t9W2+EtP5
         zftoNUDecBH/64xWZzytsN8/3kZBhVp4ur4Zo81LLpoa66OJiRFFQZhFR2kMhF44MZ3n
         VvKQ==
X-Gm-Message-State: AFq9FYI0UrIlbcRUrvoGgcWxCQ78chTfzQUF5PUOB1RNGqDs3+X26noJ
	63K/Kg+WWr93sCm9e5eIOr/ogkZrhCD+3QzT37keqqW2FFsu5aqElpo6bweE9g==
X-Gm-Gg: AYBFou2HyrA0jLoIKxS4y8zirOsAq3n+8JxESlk00HSYYa1Cdolbhm7wBz78SFTbSiL
	svM3Y3WebNXbOsFqYwW8fgvq4gl8HsZrT7/lilQSwEq2eQp6ShfF/IiK2Tgz7gmIVF9ylKv2Tci
	IQ7ed+iIS5BVfqx9hSR1VpsSTbvg8BgSUiS08FCdyP2lFHKc2HYPIFLa8XftHLAzhE2t1vLfaYm
	0yxLUUKP1pMRxAREmN8CcA1rmwrF5N/nxW8Ahb0wLYF0DNgZ0IVC+J7byU62ZiqajEuv7xPwdbS
	Kpd6QFB/0f8gCKh5DRLjmbZfhdGSfthn7KOyifZVpRKcGs6+t2lfKxIhfKoE0yHYYDubY17AMQe
	vaavo0m5MO7QE+xdW9L76QuBSo82JeZ7uVF0uYCqE6zVYhZL8VAsClYEZjdJD8wljDZm+mxD7qY
	Iev3UfLFNLQmVqtKn7aG4xDLRRpjzb8aX9zxWZDdk+dkBfxGkxGZC/FHLlJyFwLfGdroFb+DAso
	wfbHBAx2Snd9xVi/4DvmTaAJASY+VoaJE+tFFJTzjT6QnLaN3a86DNCR5ab9njIBAngUjbVWJu0
	ETBabiJJRjcXvB4UabAEqmKvHWN7gir+oFcYxlUdLwrQz2WxteGaG11jOHYGpyUULhJb3ytIra0
	rDkKOHA8o6bELzaOEeH5HeOemEZeYY1/HbtCAehsSKOtrncqb1p3FjhBkK4xyJpdviw==
X-Received: by 2002:a05:6000:46cb:b0:48d:f4ea:49c9 with SMTP id ffacd0b85a97d-48e385af64amr1160144f8f.54.1792740388729;
        Fri, 23 Oct 2026 00:26:28 -0700 (PDT)
X-Received: from christian--20230123--2G7D3 ([62.35.114.108])
        by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e38055da4sm3228024f8f.43.2026.10.23.00.26.27
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 23 Oct 2026 00:26:27 -0700 (PDT)
X-Cc: Junio C Hamano <gitster@pobox.com>,
	"brian m . carlson" <sandals@crustytoothpaste.net>,
	Patrick Steinhardt <ps@pks.im>,
	Elijah Newren <newren@gmail.com>,
	Jeff King <peff@peff.net>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Christian Couder <christian.couder@gmail.com>
X-Mailer: git-send-email 2.56.0.215.g47fdf2208c
X-In-Reply-To: <20261023072559.3204273-1-christian.couder@gmail.com>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list