Article View: linux.kernel.git
Article #885[PATCH v3 2/4] pack-write: lift and expose index-pack report parsing
From: Justin Tobler
Date: Tue, 20 Oct 2026 13:28
Date: Tue, 20 Oct 2026 13:28
126 lines
14832 bytes
14832 bytes
Once git-index-pack(1) finishes writing a packfile, it reports the
hexadecimal name of that packfile on stdout prefixed with either "pack"
or "keep" depending on whether a ".keep" file was also created alongside
it. Callers that are required to manage the lifecycle of ".keep" files
parse this report via `index_pack_lockfile()`, which provides the path
to the temporary ".keep" file.
In a subsequent commit, the "files" ODB transaction begins creating the
pack lockfiles during transaction commit instead of eagerly staging them
in the transaction quarantine directory with the packfile. Extract the
generic parsing logic for the git-index-pack(1) output into
`read_index_pack_report()` in preparation for recording the names of
newly written packfiles.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
pack-write.c | 56 ++++++++++++++++++++++++++++++++++++++--------------
pack.h | 10 ++++++++++
2 files changed, 51 insertions(+), 15 deletions(-)
diff --git a/pack-write.c b/pack-write.c
index b1311c9923..2ed33448ba 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -469,11 +469,16 @@ void fixup_pack_header_footer(const struct git_hash_algo *hash_algo,
fsync_component_or_die(FSYNC_COMPONENT_PACK, pack_fd, pack_name);
}
-char *index_pack_lockfile(struct odb_source *source, int ip_out,
- int *is_well_formed)
+int read_index_pack_report(struct repository *repo, int ip_out,
+ struct strbuf *pack_name, int *is_keep)
{
+ const int len = repo->hash_algo->hexsz + 6;
char packname[GIT_MAX_HEXSZ + 6];
- const int len = source->odb->repo->hash_algo->hexsz + 6;
+ int is_keep_ignored;
+ const char *name;
+
+ if (!is_keep)
+ is_keep = &is_keep_ignored;
/*
* The first thing we expect from index-pack's output is
@@ -482,24 +487,45 @@ char *index_pack_lockfile(struct odb_source *source, int ip_out,
* bytes of prefix, `hexsz` bytes of name, and a trailing newline. A
* "keep" prefix tells us that index-pack has also created the
* corresponding ".keep" file.
- *
- * In the "keep" case, we need it to remove the corresponding ".keep"
- * file later on. If we don't get that then tough luck with it.
*/
- if (read_in_full(ip_out, packname, len) == len && packname[len-1] == '\n') {
- const char *name;
+ if (read_in_full(ip_out, packname, len) != len || packname[len - 1] != '\n')
+ return -1;
+
+ packname[len - 1] = 0;
+ if (skip_prefix(packname, "pack\t", &name))
+ *is_keep = 0;
+ else if (skip_prefix(packname, "keep\t", &name))
+ *is_keep = 1;
+ else
+ return -1;
+
+ strbuf_addstr(pack_name, name);
+
+ return 0;
+}
+char *index_pack_lockfile(struct odb_source *source, int ip_out,
+ int *is_well_formed)
+{
+ struct strbuf pack_name = STRBUF_INIT;
+ char *lockfile = NULL;
+ int is_keep = 0;
+
+ if (read_index_pack_report(source->odb->repo, ip_out, &pack_name, &is_keep)) {
if (is_well_formed)
- *is_well_formed = 1;
- packname[len-1] = 0;
- if (skip_prefix(packname, "keep\t", &name))
- return xstrfmt("%s/pack/pack-%s.keep",
- source->path, name);
+ *is_well_formed = 0;
return NULL;
}
+
if (is_well_formed)
- *is_well_formed = 0;
- return NULL;
+ *is_well_formed = 1;
+
+ /* If there is no ".keep" file, then there is no lockfile to return. */
+ if (is_keep)
+ lockfile = xstrfmt("%s/pack/pack-%s.keep", source->path, pack_name.buf);
+
+ strbuf_release(&pack_name);
+ return lockfile;
}
/*
diff --git a/pack.h b/pack.h
index ada506b5c5..2f2ce97c11 100644
--- a/pack.h
+++ b/pack.h
@@ -106,6 +106,16 @@ off_t write_pack_header(struct hashfile *f, uint32_t);
void fixup_pack_header_footer(const struct git_hash_algo *, int,
unsigned char *, const char *, uint32_t,
unsigned char *, off_t);
+
+/*
+ * Read the report that git-index-pack(1) writes to its standard output after
+ * the packfile is written. The hexadecimal name of the packfile is appended to
+ * `pack_name` and, if `is_keep` is non-NULL, it is set to indicate whether a
+ * ".keep" file was written. Return 0 on success and a negative error code on
+ * failure.
+ */
+int read_index_pack_report(struct repository *repo, int ip_out,
+ struct strbuf *pack_name, int *is_keep);
char *index_pack_lockfile(struct odb_source *source, int fd,
int *is_well_formed);
--
2.56.0.173.gf57c9a7388
Technical Details
Message-ID:
<20261020132900.1208343-3-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-72524-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-72524-linux-kernel-git=dewy.ru
From: jltobler@gmail.com (Justin Tobler)
Newsgroups: linux.kernel.git
Subject: [PATCH v3 2/4] pack-write: lift and expose index-pack report parsing
Date: Tue, 20 Oct 2026 08:28:58 -0500
Organization: Usenet Network
Message-ID: <20261020132900.1208343-3-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="3861590"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:6JYdRCPxIdagS8NP97hR/KfVhaI= sha256:4Qbdu/u1MHt6FtG07Fr5s6aghChgztC7F3TIYfd5KJk=
sha1:mFlwTXkUCyiveVtXDBgvdWGxIss= sha256:/R2bgVcEqYwM2bkphEHiolFEjSfdTH9s1KyA0M0uBMA=
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 97603110D0D; Tue, 20 Oct 2026 16:35:34 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.048
X-Spam-Status: No, score=-2.048 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] 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 KXOZFIbZN6K6;
Tue, 20 Oct 2026 16:35:32 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-72524-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 1CCFE110CDF; Tue, 20 Oct 2026 16:35:23 +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 5A43C615188; Tue, 20 Oct 2026 13:29:15 +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=1792502952;
b=bUrRgeTJuFH7SZjr4g3bJx5O/G5XGH42dBaGsJOP3NuTcgKViHEIGunfqeorghUUONeO
LrsK4UXRjC0OCZkisol64ausuZ/GvoZo+ZiY5EBuk5APSe5CMiGRQ3HxQJzNULibbUivU
SKhlF8jggxtgHRgdxpKoocN9q70FxRLr+Ln359EL/6HKoMzRzO0fqTvQ0cILMyIAs0uRy
+v0eqU1VEKU31nWkswuPdcc4RCCGwFwWvrGAKj4x/A4DEhmFdku6Jb4rTVzoSGR9wnNkl
qs0Z013yL9bNDf/J2VCU3BUFXkI8lZGG6/xCfoY38St79NzIFIOIdo3DQyQYaZ33PzQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792502952;
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=9XABZq0Ng24cqCwSe44YEuAdjKVvWaINI5H7fTB73JQ=;
b=ql7bRcH5EzOYTMJJ7FKVB20ChgZ2ocMzlLUJEYl3Df74jwcJTP5eQVUV+j/F3fhKq1WB
Gm/5TCH9P7tuGZLJAhZx4tLJM4YAIDSROfUjndNegxu35TcO+pY6kUz+SapVfBID4zmHD
4w6Y5lsOjj0f10cQh8bK6XEmbCE/DEyeFSkTXJwwaKJhtNKpxSPku5gTOGmlLoNC2UwH2
7vtX39bd/wHQM9KyGS9wX6ZrQ8selVBlYJ2AE66HMj5QdRjipxvF3fEmSU4uVR3eRL8lZ
0Dz1Mm+iQvDEgDz81cUe2naargGuRoDGokh0P38UxonG/yCuipl66WHwAr+Vf0NuXzQ==
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=XeR8XCWV;
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 95547606A319;
Tue, 20 Oct 2026 13:29:12 +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=XeR8XCWV
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=1792502951;
b=UschHpx4gbp5PgGMr87lcvFFFb3WUg+Szw2jH5ESss15aV/y9gTwhgwH5XRfmUHrq+YP
NLSsS97pJ76F2hiQNNHKQ5qWrMc9dSA/L72z5DOgjggT0j+hOSJxxtbnjsqomhBloHh7R
+O3e6v3Svop2Rg/FtWz8Rc1QKPacIU19hfTWXx38MNnplnorCoOBpc4lnpTOl6szSlPNX
CRxymlSiwh1akYpVVfdSHq9QiykdUflm4wtU04RwTgO/zMA9VWKyzK7rcPQZttSwVQ3Ra
3tZ+gGXAFJLUsUohC6z17gzbesf0A/Kqvsfu/ZOm+O/CVq/apvxTPXN9j5WoaxZQynQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792502951;
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=9XABZq0Ng24cqCwSe44YEuAdjKVvWaINI5H7fTB73JQ=;
b=qbRJu+TpJOUvp6II1UtHgv7YWbv/RuOgaJ/i+NnQt8MBQgThGsWBZ6Gfdt/D2g4yClAz
j3npgEpYUel6dk9ojKDkK2t+j8M5RF2cdDB4Mhkh+5p33QWdtZY98T2lBpEut5Yqew1vI
qBawWJCdOyWNtRfQWmwtZcYKYFaD9OIMSEkgDo35xfGnpmEipc+XM/jbc1A7W++Jk2qps
rYUhNeYXwemGTOAxeVDxIzVpl81RZVKQ1hKeZYzXP1BGMQvMoWjgh681L++rXE2GJZIxl
Xj3R5okMVeqbC9e+fymPkIKpOinoGdZ1RNvBcvxxNw9/EGAlO0+IRp1/85mLDfH978g==
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=XeR8XCWV;
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 669B0606A324
for <git@vger.kernel.org>; Tue, 20 Oct 2026 13:29:11 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 669B0606A324
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-6ddef424972so1990466eaf.3
for <git@vger.kernel.org>; Tue, 20 Oct 2026 06:29:11 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792502950; x=1793107750; 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=9XABZq0Ng24cqCwSe44YEuAdjKVvWaINI5H7fTB73JQ=;
b=XeR8XCWVqRF8AZuKtGJePCJtsJYEzvqCqIjdbw6QDSBCPGYuAKJJwhVAXgy/8scdmp
VdGAR1clvxeIfnlyVXUorcTG8Ghpz2ODo4y3EqdxZUNNxhMzepyJaUt+LteIyMXpEECl
/aBNT1KZAJBV+EMi9LkuC5OCt/fxP933OrfvnNX/BBtCpgdT9EBtERKGPr1ri9Ib8RRB
B9OF2VWp1tz44jifRN4JxuDVek9iWex66SsO5e1/C1xLGPXR0JhepoymR+NiNmKVysyy
7lXrYX2nYreZfNpYq5uLfAohIXi6pXZD9b21OdWoxeexRQmNW6Ef+WbeVhNb+l7qZ8XJ
CxDQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792502950; x=1793107750;
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=9XABZq0Ng24cqCwSe44YEuAdjKVvWaINI5H7fTB73JQ=;
b=0xCmiOgqcwbX+bh76XAqTbVqyXoLH7OP/RpQbQECjQpMfv0ev3ccpyAEPlooDGhed3
kzirZA68ORtEB38bKGty0oC+a0tVif6gxMujq4gIdTfMLZcINy5djkZdSw+3aR+nSVMT
oN3CP8EHxmmozhMdJ4dISPrmnonMGbicCXcGTRsSAWlakf570fk33e4FaKreESmDUtoh
UDa2oBQk7g2++9aXPx/BjJRgZffuWgtkx9PbjNebToen9m1tXmSjTxWJrHkTc5kN32r1
nT9ceYnol+TnvXDAVUXV0gnum6AKCP8oLxST2lwcIwj1axc4gkYH+4ozUoOInLcCE6CO
fv+A==
X-Gm-Message-State: AFq9FYLI07LXhv5B9iTFMl5SkPsB1PuLK/Wd2BdU55EFPXOEbzEokfmI
h260G2O42h4E/r32mvxi26T9fFgjNoLJu9JtbolIfnKiJuK94O7bEKwCrPcfiA==
X-Gm-Gg: AYBFou1Sip54nQ41xau2Ps5DrcTi+BXSRHgCP46lAHeSJZ1vRt4CkyFowVWnJ9J5hMR
YcdkICYmsNGhAre+9oSA1HsqPCk4buOZV9Ya7Wvmx3fDIMKxq5otXyPQhd1Kk+fMdzlSLSU1ujF
mcEuIu2Ni9VMp+zqSlbiZKWAhjH+LxcV73YrVwnycJUMjkWCajWPBwi2c2n1ektz59+kljQCESL
KVt7dr8OAEsyzCrqu6h9PpmjTpZ1OD5mRvaTPAINKM1mU18lTCob8nwOOO7aARlEW5HX72Al1AB
sfGNwn7xDYcjwnphPRfuYBsyGDcVFlLwjaLlubE7RTxEnFuH8GhtL1zMxuPDI/AZjY+u6gjTTlD
fkK7qmKjdj+gupFGO4yxe819SMxCwjgFnd1rGffmDYWnuEOXpEjOUREmH6HEem/M+6PovE4PFP6
TgN0OZzsjtkA7Llltr3JH17dxJDKAIdfybTT4K/urrohR/8ayvHzyJ1srb9aM276r+jidb6C2Zg
fJ/XtntHSkbgogqa9Vx6bHeUgVs9mI8yt/CQg==
X-Received: by 2002:a05:6820:1354:b0:708:b419:488c with SMTP id 006d021491bc7-708b4195334mr284009eaf.84.1792502950239;
Tue, 20 Oct 2026 06:29:10 -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.09
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 20 Oct 2026 06:29:09 -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