Article View: linux.kernel.git
Article #1883[PATCH v3 3/4] loose: lift loose object index writing logic into helper
From: Justin Tobler
Date: Thu, 29 Oct 2026 23:22
Date: Thu, 29 Oct 2026 23:22
123 lines
14392 bytes
14392 bytes
Writing the in-memory loose object map to a "loose-object-idx" file is
handled via `repo_write_loose_object_map()`, which always writes the map
into the primary object directory. In a subsequent commit, a separate
"loose-object-idx" file is staged prior to commit and must be
constructed from a loose object map not attached to the primary loose
object source.
Extract the logic for writing a loose object index file into a separate
`loose_object_map_write()` helper function that allows callers to
explicitly specify both the loose object map as well as the file
descriptor to write the entries to. Note that the responsibility of
locking the file being written to is left to callers so that it is
possible for a lock to be held for longer than just this single
operation.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
loose.c | 69 +++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 45 insertions(+), 24 deletions(-)
diff --git a/loose.c b/loose.c
index 5f72c644f9..f2e111c25e 100644
--- a/loose.c
+++ b/loose.c
@@ -146,25 +146,17 @@ int repo_read_loose_object_map(struct repository *repo)
return 0;
}
-int repo_write_loose_object_map(struct repository *repo)
+static int loose_object_map_write(struct repository *repo,
+ struct loose_object_map *loose_map, int fd)
{
- struct odb_source_files *files = odb_source_files_downcast(repo->objects->source);
- kh_oid_map_t *map = files->dirs->loose->map->to_compat;
- struct lock_file lock;
- int fd;
+ kh_oid_map_t *map = loose_map->to_compat;
+ struct strbuf buf = STRBUF_INIT;
khiter_t iter;
- struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
-
- if (!should_use_loose_object_map(repo))
- return 0;
+ int ret = -1;
- repo_common_path_replace(repo, &path, "objects/loose-object-idx");
- fd = repo_hold_lock_file_for_update_timeout(repo, &lock, path.buf,
- LOCK_DIE_ON_ERROR,
- LOOSE_OBJECT_IDX_LOCK_TIMEOUT_MS);
iter = kh_begin(map);
if (write_in_full(fd, loose_object_header, strlen(loose_object_header)) < 0)
- goto errout;
+ goto out;
for (; iter != kh_end(map); iter++) {
if (kh_exist(map, iter)) {
@@ -173,24 +165,53 @@ int repo_write_loose_object_map(struct repository *repo)
continue;
strbuf_addf(&buf, "%s %s\n", oid_to_hex(&kh_key(map, iter)), oid_to_hex(kh_value(map, iter)));
if (write_in_full(fd, buf.buf, buf.len) < 0)
- goto errout;
+ goto out;
strbuf_reset(&buf);
}
}
+
+ ret = 0;
+
+out:
strbuf_release(&buf);
+
+ return ret;
+}
+
+int repo_write_loose_object_map(struct repository *repo)
+{
+ struct odb_source_files *files = odb_source_files_downcast(repo->objects->source);
+ struct strbuf path = STRBUF_INIT;
+ struct lock_file lock;
+ int ret;
+ int fd;
+
+ if (!should_use_loose_object_map(repo))
+ return 0;
+
+ repo_common_path_replace(repo, &path, "objects/loose-object-idx");
+ fd = repo_hold_lock_file_for_update_timeout(repo, &lock, path.buf,
+ LOCK_DIE_ON_ERROR,
+ LOOSE_OBJECT_IDX_LOCK_TIMEOUT_MS);
+
+ if (loose_object_map_write(repo, files->dirs->loose->map, fd) < 0) {
+ ret = error_errno(_("unable to write %s"),
+ get_lock_file_path(&lock));
+ goto out;
+ }
+
if (commit_lock_file(&lock) < 0) {
- error_errno(_("could not write loose object index %s"), path.buf);
- strbuf_release(&path);
- return -1;
+ ret = error_errno(_("unable to write %s"), path.buf);
+ goto out;
}
- strbuf_release(&path);
- return 0;
-errout:
+
+ ret = 0;
+
+out:
rollback_lock_file(&lock);
- strbuf_release(&buf);
- error_errno(_("failed to write loose object index %s"), path.buf);
strbuf_release(&path);
- return -1;
+
+ return ret;
}
static int write_one_object(struct odb_source_loose *loose,
--
2.56.0.173.gf57c9a7388
Technical Details
Message-ID:
<20261029232220.1245827-4-jltobler@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-73837-linux-kernel-git=dewy.ruReferences:
<20261029002413.3291184-1-jltobler@gmail.com> <20261029232220.1245827-1-jltobler@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-73837-linux-kernel-git=dewy.ru
From: jltobler@gmail.com (Justin Tobler)
Newsgroups: linux.kernel.git
Subject: [PATCH v3 3/4] loose: lift loose object index writing logic into helper
Date: Thu, 29 Oct 2026 18:22:19 -0500
Organization: Usenet Network
Message-ID: <20261029232220.1245827-4-jltobler@gmail.com>
References: <20261029002413.3291184-1-jltobler@gmail.com>
<20261029232220.1245827-1-jltobler@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2120832"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:TkCZA0NzwNIwNOO1G8HzkOl+EGo= sha256:eyGAczrtHA+ZalzaucgAAJE6XZi38+bRzz58FWXZg8Y=
sha1:03ikO1TyXlNGb/Bi0Op8Tf2OdaI= sha256:C60KQ9+4PvYLDcpCDHB5gDMa5WwQI6fYmT5SZYQPrfE=
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 7AF67125C7E; Fri, 30 Oct 2026 02:23:19 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.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] 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 Ut7fYSc-LK2v;
Fri, 30 Oct 2026 02:23:17 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-73837-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id E9703125C6E; Fri, 30 Oct 2026 02:23:08 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 024022A51B; Thu, 29 Oct 2026 23:22:55 +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=1793316170;
b=KFkS6bU8u6sHIFewxJviotkfcE/aFKKfjFoZymJQ4AfBQ2thczMp54SirGp1pXfCtozI
yQl6hTtoIJ3BSFKa8+i3lRyJ9FpWn5vF/gl6mDHowkaVUb2UTwYHotGfWH/nCUCFtpZIV
w6eLjOb/WeulyNo1uyqGNXqTc6V4zu360I7vwSIEkDBP2WWaairNRxOFP57AZeywTqyKA
MOH53wp5blhVaRntW3mR2iaYlm9fTatWhhNXp3l80oUDcjK3OSwVAjVBvR3vdE6x7f6dM
8HXsMVokE79rBOBmp8FS+T79q/sEMyp18ig2OQK2Cr41rEOjQaSFrP6EQXSfOYyl5nQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793316170;
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=yXk1vWkutxy2NEI7qhaehqXO7HsvV0ZGl+rs7qlvjNE=;
b=Jzu4VTUv6zJtvT3cE9XwBpWqejy7ow3xKNhOgLG4ff0Vp5F33fbPkmPfvtFsygSGTVqp
D8McSM05cCPgA0xJwqRcwwghyetxjeFWWFAF4F+9AIvOaMSthbMVEYzNZ8fVZ0zZXgIiG
v0n+tR5xLgf8QerhvLDBdVI678XNcK2R99ujsLO4RL8HdhXJOAqdvf8bZwXA/vL0IgAM+
MiAAZzvqe0Vo237QbqhzmZG6I8v60rZ3Ni1YmRWS12LXFr6VLL8f5AM2d1uwbaJojQf7B
AAD1z/c4WgweEMHXlwX+SZbvkax6DUvScUbtC1ngj7TeUwIhkWBSAovQYrQiC6l4Jkg==
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=20260707 header.b=WNr7yFnn;
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 032A9606A31F;
Thu, 29 Oct 2026 23:22:50 +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=20260707 header.b=WNr7yFnn
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.44
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793316169;
b=qHmW4dfyRIjptOvGfsHryuFKEsrrzjuTDKKVG69C8WxtQcLpzBR0KaHIgdV5mpPvSu/d
Ab9hzOnQbkXLnEg6vlaNNph4jnn2H+W+AosVeDU7cVZIFtJ6qNIaBksXY49SsNFnqH8Da
09gWvRM4m+hhhNLStZ+r0i3pw35iGtaQutlkY2NQPkdps1lxrZl5dB4nZSg4zjqUfABCu
820eTWWWalrHAmSmDeTjcFbqO/+kFNitFg92EriNsekYgs9UYyKDPlZnIRSm01R0dX/38
iy3iaTH9q+JNk4mNhj2EMjMVarX3VvNZtStDAcq8bUuYNCG9UM4M75Vwzm1hJiHgUCQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793316169;
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=yXk1vWkutxy2NEI7qhaehqXO7HsvV0ZGl+rs7qlvjNE=;
b=dKKnTps/w3tuF7QEIrckM878wB0YJmpzzS+I7lGM/hlru8rIbiGQA55sqXd1uPNJa5NU
AtRWhlimghNuOoEaMszI3S1LXodN8i7I6ZpDv0GH20Ap0HVgLywqTV8mPg/NuIEAoqH2C
/5w4KzUo+uoul/GAiBVCZb8fpz0Ol4Gbgdc5hCEkY+JCKOpxQXaw1l6c9xfcrDWhgOERc
8PmzmzvoY3PaD55opO/jOPhZfAp2AnYL37h0d9irrQTWlKpFccCKwDIGpdB1+JtFoq8I0
ApOn/6upy3rfxnHAwfDv1qTOEVAryPp1FxezBI9KH4RLTltfH4KJJlLctsQq48L62Bg==
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=20260707 header.b=WNr7yFnn;
arc=none smtp.remote-ip=209.85.161.44
X-Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44])
(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 C5E08606A339
for <git@vger.kernel.org>; Thu, 29 Oct 2026 23:22:48 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C5E08606A339
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-oo1-f44.google.com with SMTP id 006d021491bc7-6fe4372c5f3so74853eaf.3
for <git@vger.kernel.org>; Thu, 29 Oct 2026 16:22:48 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1793316168; x=1793920968; 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=yXk1vWkutxy2NEI7qhaehqXO7HsvV0ZGl+rs7qlvjNE=;
b=WNr7yFnnuvGl3mKH2sSwthvq39q9uK0h5xAEm8EokKcedihulhfAjfd6ryzZXrsfMU
bJFWieHPqp3KJVzCu20bP6eWmUWj+Bj/4YhviXS+oRVCReiRcMT9AZU1VPco6owEvxiq
62VqpiMI9VsEMgh3IOiBHM5zB2fJo4SGgU+sDQGi4OSQeBz/b0ErEDEYohQV1WIVQBTG
1wVQuIMdRPbe1HdbL9SQFJyr/FqRFkE0dRwSqPTFYskTbwiy83cZX5IWmF+iueCV3ufm
s6MsFdD+v+H/sK+wbBTcg2lJdb3Yw7QmN/BYitHCUTp/haVS4Jo3tesXw+6P/G7hqAk7
SDrg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793316168; x=1793920968;
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=yXk1vWkutxy2NEI7qhaehqXO7HsvV0ZGl+rs7qlvjNE=;
b=uF0zgvkdNWBPl4mfVx7mD3zYrqg3Q3smdLp5ZivpIWT9tLBEU3CYFnqtWl+HY76xjk
rQQV0YLxGuytLXr+mdx/83LqeCnJuGXycW4q+z6ux34c2s6+QYHCT2MUbWfZhHP9VY3E
KSyHBGwkvJih3DochihmFVnnvNxLF9LNi+iQ6/wpQqehXk/nVEc2g9Eg79RyCOz+DKML
rT6ffEIOv5kBqPX/HVgC2cxNvYDjLTRr5wIe7lWdOTT1jFmDM37oTLvm3DKdLZ+OJuzV
lKA8El4P6I6V651AlXKQE2aVazWfMDlsaAWc135/yBifeHJLNE0xEdpilbSXVeS90F6T
hytA==
X-Gm-Message-State: AFq9FYLX07m8eQS2629ChbAf/fqT2I+96099Grsj2eAWNZyhFyrtMINL
ci4Bo/kS0rIgPvhbRNVe/NP9cX/wZMEmra4hMZqY+LtAaC3IP83VNyjjtAPjVw==
X-Gm-Gg: AYBFou2kJGo9RmFacIpkbx1aLF72GW4QxouzlxubdeMXdMsKPthsbUA2mR2IjT6BoUs
U474QRbsvVwmH9CjVBmb3wRCo2CJaQCNCj4pMU3aWfS2Y0tlra3FspX8lVT5+CZ3MWA1QSe3ehy
kh9TFek4ncrDFjAycgkEFDtW4MJLENAUU0KSM3Lny8eG1vUMJTJ2IzFexDSGkmEVlxsAS00SqNN
FiXuLp6UjaJ7nji9IYs47JjFy4bfpMEjJ7+3WJnAGrQCpBCpwKOZtMvRmJlxVeiWT/sUQb3CyDW
KIIGPG3uuHmM7QTIy9ug11g1+NMJFCcrIkskIkEaBaJ4+24qLjJozVXgQhXBrCX6Dcux0BajE6D
kdbW+X/+xv4ocADQex22F84xppuGBceJzf3NhbmVfF5Fwa8ja9KuZJ9Ec+qpM9wLNU2loRRqblB
tHkohCR9voJtnYycU35BJgIurMLeT/vEfzb83Z7X8gYgzf3my36YNxaw/u2iJQ4gE4BszB4M0Qy
D6uWb6dzgdqTsbBpo8Odk2rFuhRh/9+uYVlnNAcfbkHIQZIpu9ggxRo076ilheCvcZtzuRwOTZX
gkogWcOaROQt8g8RujZFh757MR8VgMaRZsMMFGGV4SxAotG7UKY23UVI+45HrgfF5Az4
X-Received: by 2002:a05:6820:f00e:b0:6da:453d:7cd4 with SMTP id 006d021491bc7-714f2945a30mr591861eaf.23.1793316167773;
Thu, 29 Oct 2026 16:22:47 -0700 (PDT)
X-Received: from denethor.localdomain ([136.51.44.64])
by smtp.gmail.com with ESMTPSA id 46e09a7af769-85d354d05e0sm694924a34.15.2026.10.29.16.22.46
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 29 Oct 2026 16:22:47 -0700 (PDT)
X-Cc: ps@pks.im,
Justin Tobler <jltobler@gmail.com>
X-Mailer: git-send-email 2.56.0.173.gf57c9a7388
X-In-Reply-To: <20261029232220.1245827-1-jltobler@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