Article View: linux.kernel.git
Article #887[PATCH v3 3/4] object-file: explicitly write ".keep" lockfile
From: Justin Tobler
Date: Tue, 20 Oct 2026 13:28
Date: Tue, 20 Oct 2026 13:28
179 lines
16276 bytes
16276 bytes
The `odb_transaction_write_pack()` interface for the "files" backend
relies on git-index-pack(1) to write the specified packfile into an ODB
transaction as a packfile. To prevent a concurrent housekeeping
operation from deleting the newly written packfile prior to the
references being updated, a ".keep" lockfile is also generated by
git-index-pack(1) via the `--keep` option. Consequently, the ".keep"
lockfile is written into the ODB transaction alongside the packfile and
later migrated together to the primary ODB during transaction commit.
In a subsequent commit, writing the lockfile is deferred until
transaction commit and thus cannot rely on git-index-pack(1) to write
it. In preparation for this, update `odb_transaction_files_write_pack()`
to explicitly generate the same ".keep" lockfile itself.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
object-file.c | 105 +++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 83 insertions(+), 22 deletions(-)
diff --git a/object-file.c b/object-file.c
index 210984f825..ad55c01198 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1256,6 +1256,45 @@ int read_loose_object(struct repository *repo,
return ret;
}
+static int write_pack_lockfile(struct odb_source *source, const char *pack_name,
+ const char *keep_msg)
+{
+ struct strbuf lock_path = STRBUF_INIT;
+ struct strbuf contents = STRBUF_INIT;
+ int ret = 0;
+ int fd;
+
+ strbuf_addf(&lock_path, "%s/pack/pack-%s.keep",
+ source->path, pack_name);
+ strbuf_addf(&contents, "%s\n", keep_msg);
+
+ fd = safe_create_file_with_leading_directories(source->odb->repo,
+ lock_path.buf);
+ if (fd < 0) {
+ ret = error_errno(_("unable to create '%s'"), lock_path.buf);
+ goto out;
+ }
+
+ if (write_in_full(fd, contents.buf, contents.len) < 0) {
+ ret = error_errno(_("unable to write '%s'"), lock_path.buf);
+ close(fd);
+ unlink(lock_path.buf);
+ goto out;
+ }
+
+ if (close(fd) < 0) {
+ ret = error_errno(_("unable to close '%s'"), lock_path.buf);
+ unlink(lock_path.buf);
+ goto out;
+ }
+
+out:
+ strbuf_release(&lock_path);
+ strbuf_release(&contents);
+
+ return ret;
+}
+
static int odb_transaction_files_commit(struct odb_transaction *base)
{
struct odb_transaction_files *transaction =
@@ -1348,9 +1387,13 @@ static int odb_transaction_files_write_pack(struct odb_transaction *base,
container_of(base, struct odb_transaction_files, base);
struct repository *repo = base->source->odb->repo;
struct child_process child = CHILD_PROCESS_INIT;
+ struct strbuf final_path = STRBUF_INIT;
+ struct strbuf pack_name = STRBUF_INIT;
+ struct strbuf keep_msg = STRBUF_INIT;
struct pack_header hdr;
const char *hdr_err;
int err_fd = opts->err_fd;
+ int ret = -1;
int status;
hdr_err = parse_pack_header(&hdr, pack_fd);
@@ -1390,17 +1433,12 @@ static int odb_transaction_files_write_pack(struct odb_transaction *base,
}
} else {
char hostname[HOST_NAME_MAX + 1];
- char *lockfile;
strvec_pushl(&child.args, "index-pack", "--stdin", NULL);
push_header_arg(&child.args, &hdr);
if (xgethostname(hostname, sizeof(hostname)))
xsnprintf(hostname, sizeof(hostname), "localhost");
- strvec_pushf(&child.args,
- "--keep=receive-pack %"PRIuMAX" on %s",
- (uintmax_t)getpid(),
- hostname);
if (!opts->quiet && err_fd)
strvec_push(&child.args, "--show-resolving-progress");
@@ -1424,34 +1462,57 @@ static int odb_transaction_files_write_pack(struct odb_transaction *base,
return -1;
}
- /*
- * The lockfile filepath is expected to be the final location of
- * the ".keep" file after being migrated to the main ODB source.
- * This ensures the lockfile can be found and removed later
- * after the ODB transaction has been committed.
- */
- lockfile = index_pack_lockfile(base->source, child.out, NULL);
- if (lockfile) {
- ALLOC_GROW(transaction->pack_lockfiles,
- transaction->pack_lockfiles_nr + 1,
- transaction->pack_lockfiles_alloc);
- transaction->pack_lockfiles[transaction->pack_lockfiles_nr++] =
- register_tempfile(lockfile);
- free(lockfile);
- }
+ ret = read_index_pack_report(repo, child.out, &pack_name, NULL);
+
close(child.out);
status = finish_command(&child);
if (status) {
strbuf_addstr(err_msg, "index-pack abnormal exit");
- return -1;
+ goto out;
}
+ if (ret) {
+ strbuf_addstr(err_msg, "index-pack failed to report pack name");
+ goto out;
+ }
+
+ strbuf_addf(&keep_msg, "receive-pack %"PRIuMAX" on %s",
+ (uintmax_t)getpid(), hostname);
+
+ if (write_pack_lockfile(transaction->quarantine, pack_name.buf,
+ keep_msg.buf)) {
+ strbuf_addstr(err_msg, "lockfile write failed");
+ goto out;
+ }
+
+ ALLOC_GROW(transaction->pack_lockfiles,
+ transaction->pack_lockfiles_nr + 1,
+ transaction->pack_lockfiles_alloc);
+
+ /*
+ * The lockfile filepath is expected to be the final location of
+ * the ".keep" file after being migrated to the main ODB source.
+ * This ensures the lockfile can be found and removed later
+ * after the ODB transaction has been committed.
+ */
+ strbuf_addf(&final_path, "%s/pack/pack-%s.keep",
+ base->source->path, pack_name.buf);
+ transaction->pack_lockfiles[transaction->pack_lockfiles_nr++] =
+ register_tempfile(final_path.buf);
+
odb_source_prepare(transaction->quarantine,
ODB_PREPARE_FLUSH_CACHES);
}
- return 0;
+ ret = 0;
+
+out:
+ strbuf_release(&final_path);
+ strbuf_release(&pack_name);
+ strbuf_release(&keep_msg);
+
+ return ret;
}
static int odb_transaction_files_finalize(struct odb_transaction *base)
--
2.56.0.173.gf57c9a7388
Technical Details
Message-ID:
<20261020132900.1208343-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-72525-linux-kernel-git=dewy.ruReferences:
<20261016213716.593278-1-jltobler@gmail.com> <20261020132900.1208343-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-72525-linux-kernel-git=dewy.ru
From: jltobler@gmail.com (Justin Tobler)
Newsgroups: linux.kernel.git
Subject: [PATCH v3 3/4] object-file: explicitly write ".keep" lockfile
Date: Tue, 20 Oct 2026 08:28:59 -0500
Organization: Usenet Network
Message-ID: <20261020132900.1208343-4-jltobler@gmail.com>
References: <20261016213716.593278-1-jltobler@gmail.com>
<20261020132900.1208343-1-jltobler@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="3862910"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:iTUJz6RD5T3InVVe9sJfBHqM6tw= sha256:RKuIHvZlJmpqW+isZreVk7QbLsqly5iKfaiTFyWdDpU=
sha1:t7jn1mMcU0UjLLKcKGdTAwemfNY= sha256:A7Icbuhrm3NT1A7WP3BANesQ4B4YvMS3ZzvigpbQ2Bw=
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 DD20C110D12; Tue, 20 Oct 2026 16:39:04 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.948
X-Spam-Status: No, score=-1.948 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, 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 KdxQ532ZL9Nf;
Tue, 20 Oct 2026 16:39:02 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-72525-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 52588110D10; Tue, 20 Oct 2026 16:38:54 +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 ACBE447FE9; Tue, 20 Oct 2026 13:29:18 +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=1792502954;
b=AEzOo1N+WH8M7kp8k9yTsF66xsQjQt8H/luXNs7tesc/PAPc6Rd5Y1ocsUGyOs6dCmJE
TnTWuDpPqjFmNvDhKwWiiN0UyTDOsTDmuU5Qew49P/xlFUtJdanR4xOQjLCh+uTYvY9AN
Ci1XsUBaTzLesB+4dn8wAfE6CPWVnmKizqXnlH9J7nrxcbiEcBEdv36k3xTKH1SwRLRjb
GW4hZQVJ7bjRgmnFVFJ8hJ0qSoobmLa7xRmAKXXOxAFiUyh7xCtPLAawzEst3XCDtuxUB
HdZpD2ctGzE37r94FTd1GTdFsTBy9KNGmCnrs+at/6ZOZyWwGVGXEG4PDQRg0T/HqUA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792502954;
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=tq14daDldnm55NmNSbuZF+jaHM7W/OTZuwIg85imYUE=;
b=dXT888AUSWrCsZEGwkWG0itqGoTeTeZm1yOaLkNYlXjJ+ESbmMaHl8/SRtC1iz9abc3s
o4j5S6kcFO6pU4sH9V5Qz6wkP+h1g5OdDfBnEORLHW23OpW8fLncBxZmiY8i4Ulhkx2Jf
tLj+5P/jX5lkKGbJAKfVa96NnWhSRJNnsWBjLuYYlVsg4TXUyqm4FjS1wuU14ycxT/JwZ
igo+be5ES12NOjICA4Fa2e9+NJlYjQ0be6x+1uSJvHms9jIOwCvYvyPf6UUn8lMZ65v6o
5BkuZ7Jy884GUEhXukZG4jCM5b5F2H2UN2jdQB0c2SdyyycE2SB34Xn/2znCbyIXVnA==
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=eIIp2YeQ;
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 98670606A334;
Tue, 20 Oct 2026 13:29:14 +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=eIIp2YeQ
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.54
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1792502953;
b=Mllgw60TRzOphP7tsQgCHJpet/TDXN+xwJ57vk09gdFTZeVAsQhq5/e23Gif4Hp56K9E
XmDcvKOisk8CmAt9ILuzMhgg9rpNB5lyjJJebJj1Gx8Atlo+I/+qjLEV9rDIwmmFmCY23
ljohJJ2ThEeJcuctskG24aNAkqb/k97EVBCC7RwFzQlMYd6tGGnwN+OQRyMr545MQM02M
OEwWKdFPnp5/1rEIW9WTJk8hJnwSuyqM7keC8H9MIMtq5YYHhfi9/GqzQAfTefHVnmX/x
Xwql4SGJWmB55x26YSvBy5z7G4bQpNqVtZ7ZkbinAlfbPoASwd79liTatihuJyIvOkw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792502953;
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=tq14daDldnm55NmNSbuZF+jaHM7W/OTZuwIg85imYUE=;
b=TqtVBKm1EnfELzHnkaCQMebDWQNuOTx3HHh9t1LChFiKN9pahR0ugeDTBvKW4s4JXdPy
6kisV7GN6Cs0zzHqAXkmU5Np0TLSsZ9ZH2f8aiThSlOg7BlOkYbJyFD7GpM651TI0fSoB
Wcnjb2mNuvjaMfOGJGUYi03ncpaoGnyDYCwF9NFLqXTU5xeYN1Zweh0l5icVlCtKh1Dre
UQLQKZ/WK4pxrmsCJTO+Zz57P3MLoVSBkHKNPrynpSK/fCQhtUYOHIca9oWXb14hykXdB
NoE8Tx6LzfNz+/ZqDlcfimKZDGh0TIfOUtcPghxIXGfL+6UpA4GXGYQ31nR6zUaDr2A==
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=eIIp2YeQ;
arc=none smtp.remote-ip=209.85.210.54
X-Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54])
(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 B1568606A330
for <git@vger.kernel.org>; Tue, 20 Oct 2026 13:29:12 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B1568606A330
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-ot1-f54.google.com with SMTP id 46e09a7af769-8198a3a54d7so646791a34.1
for <git@vger.kernel.org>; Tue, 20 Oct 2026 06:29:12 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792502951; x=1793107751; 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=tq14daDldnm55NmNSbuZF+jaHM7W/OTZuwIg85imYUE=;
b=eIIp2YeQIVEtfmh2nhE4uKEXm7Vu+Lx7Enzj5nHRhhuZH/CGwukckj3R38L14lii5S
5Y0uA2sbXfPdKJeKe+EzCN2QuMbOWiyVWJO8PCBBHevO2mYB6tUe0x/0dSmLMsY1uxTC
INNZ+NB+lCiDAIKp5MWsW6bGRaIXMa+I5nAxJzxspI3a8fIIQFvZ01HznUKLfiAe3Q8d
Lo8/d0jsDQsi3t8Va2A6G6MN9SAb94IH8eL1TlZ5qYeTnkQx4+bAbkitAfkGGVPLXTrN
qASOB5Dc7cNooWS3lG34hkDN4A9+YnV7QG++HLnYziicsHZN0fIb54yqNoEHMyJHiLv+
t+8g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792502951; x=1793107751;
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
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dIJ
AlJbtDIZqjA5YUe2R1vriZeLzYE+GIkEPEYxg==
X-Received: by 2002:a05:6820:1906:b0:6f8:51f5:b9af with SMTP id 006d021491bc7-707bab2b76dmr1247163eaf.25.1792502951617;
Tue, 20 Oct 2026 06:29:11 -0700 (PDT)
X-Received: from denethor.localdomain ([136.51.44.64])
by smtp.gmail.com with ESMTPSA id 006d021491bc7-7018f2e0d89sm9973129eaf.6.2026.10.20.06.29.11
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 20 Oct 2026 06:29:11 -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: <20261020132900.1208343-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