Article View: linux.kernel.git
Article #1785[PATCH v2 3/4] loose: lift loose object index writing logic into helper
From: Justin Tobler
Date: Thu, 29 Oct 2026 00:24
Date: Thu, 29 Oct 2026 00:24
120 lines
14226 bytes
14226 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.
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:
<20261029002413.3291184-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-73707-linux-kernel-git=dewy.ruReferences:
<20261022234007.3081825-1-jltobler@gmail.com> <20261029002413.3291184-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-73707-linux-kernel-git=dewy.ru
From: jltobler@gmail.com (Justin Tobler)
Newsgroups: linux.kernel.git
Subject: [PATCH v2 3/4] loose: lift loose object index writing logic into helper
Date: Wed, 28 Oct 2026 19:24:12 -0500
Organization: Usenet Network
Message-ID: <20261029002413.3291184-4-jltobler@gmail.com>
References: <20261022234007.3081825-1-jltobler@gmail.com>
<20261029002413.3291184-1-jltobler@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1900973"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ZotzYHEctXxwcaHOriyiwrvUJb8= sha256:eQbOILp3mKrR1UKG5f+1lGeV1U3N6BgZmwTkRxTMXwY=
sha1:CDki+ES83aNa0AIHBDGDfP1i+k0= sha256:zPXSNNIlCDFO0JeTodncXu58zkWG5QMFR93kHfLNzwI=
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 CC90F125C53; Thu, 29 Oct 2026 03:24:53 +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 3_2l7IXTlvxi;
Thu, 29 Oct 2026 03:24:51 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-73707-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 34896125C4E; Thu, 29 Oct 2026 03:24:42 +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 9F45A2A4E1; Thu, 29 Oct 2026 00:24:30 +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=1793233463;
b=Phf2EPt+STTN88aF+kTGy58QvOmoi4qk6kxRKFnm01FYywy67lOEyxXZ+EdytUklB5BC
TNM7Y4AozNkXEN+mgZQjZntSNKamLfxrGyN3kIjy4cZQREqj2FW6MLB2HgmfbD3MWuAgV
QzYC0Yx5PvtHr+t6JEzK0X3dSgEYcq71MW15xY9bgHfLE3ZCXZEdOwNshBC5jLBDuCd2v
XERAIPaPxAywAwxDR3PvXIueWao/dYwNEk9hE0S57tTr7vjWe5Wev+njeIo/XVzA5XlV9
ZRGAD0CCjAoE/fExrn7omt5r8sBFI43HSa31uvSk9FXWjRVVr8AjP7/y3HnbbFv5TDg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793233463;
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=oQMTWolzwo73s8phra6UAR/AeawSnETL+hGRjFtomsA=;
b=ubBm00q6ZtPQmlK1e61yV6qUZ2JhDS7XOzM1hTSzklQtjmHGI9KDw/mC/AZsXPi/KIMQ
BIF1y8LSZWqD4DvSqrcSyobPpgwTsTYpfoKoEePMn+p1G0huO5bazwmlqe8LwAD8qwVVN
KfzREZauXcFRwFHl1hJyYfof+KYbfeOAvj2oM+M1oFxtr8bEHfj9dxpVKIpoF9uWwN8IH
bgZQtJXU2Lu04Qf5nD+BOsYD3EVkuXnr1xZy6ynXp5Z7x2crUGZASMVAVgPpyi/AyBHhT
wL7CCSHYLkuLG6E+rVm7pgL0CsE79W1K3mGtcZX8Pr3Vaq11civto6Eph4tY/frWzrw==
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="w/QWTrq0";
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 A7C3360A2607;
Thu, 29 Oct 2026 00:24:23 +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=w/QWTrq0
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.42
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793233462;
b=XAU+fv8uRF1VSiUIdg/w74IdrKaCzc8o1WeIDZUX7U8Ujl9Ypb3K7yTqIjGgiS9PPa1u
HQiLYCbEQ7YIqyo9S1MkGOMuwv5ItAK+sPX1LoG5XaseG6lskQ1G4s+7jHup8SO55RIG9
pl7//EwGPadWlDfwwC3uU9swzP1MiKs1rBvltdtNdkGl6s+I5Z3xXJHF5iQxgqCmLKTW0
uCMEFja5N9NNAr/3bZR3Q1giiQwhRinsAJq+Jke5Ox6gv33l6ceVZyDAuL1HwsVMAj099
UgfZPzX3rkxLmKoxdWgRJVx23qUvcq19E2qmP2KrSZ23FESmb1yly/4Sw69ehbx3afA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793233462;
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=oQMTWolzwo73s8phra6UAR/AeawSnETL+hGRjFtomsA=;
b=UiwiPmUvncGik9/4xz9JZA7d3uVVghUXLEQdsXKVwjcSHjQOgG45DF/ZUGyvVkfl/e27
i2WmNaaJkyaDYd5SXDDWRDgGxCi169OTSpYa9VkS68/stSPjoE/+pbd6XaNJUEXlrTo72
b04Ycaj3bOkLrX7ep8lQTevUko74Ld79jtU1shGpVb7b7PaafHXUbgU829kgNiaegxlMP
kAB0WXWyR5V1FcA3tJm5Z9/fDaXCqaIoP+Y0zJRv7BZKBDo4f0TLzJcBFJ3nxyuc5TgjP
UFJ2shMqMi5iCvoGZmudjT0Y61fsSE59j764R/G0mgqKUjtIOBvwG72jBT7evbGPFHg==
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="w/QWTrq0";
arc=none smtp.remote-ip=209.85.161.42
X-Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42])
(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 712AF606A336
for <git@vger.kernel.org>; Thu, 29 Oct 2026 00:24:22 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 712AF606A336
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-f42.google.com with SMTP id 006d021491bc7-714d57774d8so529584eaf.1
for <git@vger.kernel.org>; Wed, 28 Oct 2026 17:24:22 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1793233461; x=1793838261; 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=oQMTWolzwo73s8phra6UAR/AeawSnETL+hGRjFtomsA=;
b=w/QWTrq0CHUdF1zVkWT+oSnW8naWdpqx60VUCP5+Ssta6AglEYJbm/GN8LYtNra+fT
tS88f7nhS9Vq+16TVflKTvA7ZPDjOooLqVGNuwjhCUWnoTgIu4jwOJFG5K8bjwUfZKQ5
B3O7su9iMYhQW+UV2vjQ2fKEFhP26P6vYfUBQBrS574fHABiAcm2NHLLC/4z6WmUJ5Lb
bfZMakv/Dpler5o21Rr6HI6UwrEPNYgoiOgZVvzXCr10C6nuRuVkcBUYRka1Pyqd7pWX
1if2j3PosY5fAvpsi7SSSjeTAiSJMbwe95tEOqBDQV3MajOblx7p9VxCSWR1BlLJzh0F
GQig==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793233461; x=1793838261;
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=oQMTWolzwo73s8phra6UAR/AeawSnETL+hGRjFtomsA=;
b=YQvffen/XTn2plKGjUKBXVYkr4gkdheWsbEp4x4E4lGmmowOCOlv7AyhHYDpJ1n0MV
lRQ0jyPa+Dn+cXBZhOb7wgOsMK4CwzYPF5UixNdpIFW5CvWHqjbj6IKhl/lZkdPqUvOK
xJA3iu1EXLs8PkjvUCwIfNn3zxv9qHaE+4aCxQQIYUwHtZkZZJVgupNekf8LPeLm684g
9l2qNBMb7OAMq8UwowWjAqn4bV4QxirtEz/npb6NdtoBPLspiHJRcIU/7ttEpDySk5Yc
+qjUFMp7EE6SiU+oWMJZgjLHbv0bWJLEgRLIXURz8CcCz+gBQkLpT3Dlqu44+08MkZq7
nIIg==
X-Gm-Message-State: AFq9FYI6iakJEeLhq1XUjn3QZI1UUXWV23CczJ8Bx4iR4XF4dCvfuysC
yOKLH/JRefaCi5/bq5mzOe5/An4uxQofbFJdZycRpikFFXTfUiAcwTfkX1mvWw==
X-Gm-Gg: AYBFou0hAaVDPPL0hSWMP96vVzSuyFqCZRSnvG07oPQno+IHbV3yPyqzo+3ntow3Ozl
CjcfkAxcXvumqoBOqdzdzHK5gfocNzrqg6e0fWLhwka5GWC+EambD9n97eMWdmCb744ngAZssKQ
GxzDnBdhTXlNLRto8UrOa9aF+coP+dfgsBd9YP235RRWJsfjT6BTbYY4KC+ja1jkdfh07gkW3BA
YiXIxfOrVO0V7upqp00hZ7vZqXiGhia3kjFbMikAeccq+r8jZ2cWPeJ/1qubJYqGHnV/jlt1RRg
kVCi6xfCHooe9abOI5mobva4z6HNbbUHBqp+T+8qaniAdfUAhcSD2yiLsr4cj+RSfYGv49vKNlo
64PKH/GRBKj3jZ4jskGKDYw+g0oEyD7RDBcZ3xpxtpVSqUkDQ6J5cu+IIYqDpTY6GxI9RAlcGfd
9JDG61n9rhA8saEkF9M5miaL5A0YaBbHRL82ETeiEFBcm+poyFQvOq1rHq0KH66iW4DN/1VMDdY
zgW7cadi/fbfPRImADOOGX1tC6A0v9+68tuhyZBIUq/VDG/XzYVCItH1LcxdhJFzgrGkmGE3iir
+sl3kihwjC4h2dx15sg6Mir8wEodjlppUdcgktNRtzCNNy4AZNDXz9pSdVR3wyWrP2iwQQ==
X-Received: by 2002:a05:6820:f014:b0:70d:a1df:7dec with SMTP id 006d021491bc7-713ef23f1camr2224823eaf.32.1793233461231;
Wed, 28 Oct 2026 17:24:21 -0700 (PDT)
X-Received: from denethor.localdomain ([136.51.44.64])
by smtp.gmail.com with ESMTPSA id 006d021491bc7-7142bb7942fsm2976439eaf.5.2026.10.28.17.24.20
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 28 Oct 2026 17:24:20 -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: <20261029002413.3291184-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