From: Justin Tobler <jltobler@gmail.com>
To: git@vger.kernel.org
Cc: ps@pks.im, Justin Tobler <jltobler@gmail.com>
Subject: [PATCH v2 2/4] pack-write: lift and expose index-pack report parsing
Date: Fri, 16 Oct 2026 16:37:14 -0500 [thread overview]
Message-ID: <20261016213716.593278-3-jltobler@gmail.com> (raw)
In-Reply-To: <20261016213716.593278-1-jltobler@gmail.com>
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
next prev parent reply other threads:[~2026-10-16 21:37 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 2:28 [PATCH 0/3] object-file: fix ".keep" lockfile ownership in ODB transactions Justin Tobler
2026-10-16 2:28 ` [PATCH 1/3] pack-write: lift and expose index-pack report parsing Justin Tobler
2026-10-16 6:58 ` Patrick Steinhardt
2026-10-16 17:30 ` Justin Tobler
2026-10-16 2:29 ` [PATCH 2/3] object-file: explicitly write ".keep" lockfile Justin Tobler
2026-10-16 6:58 ` Patrick Steinhardt
2026-10-16 18:37 ` Justin Tobler
2026-10-16 2:29 ` [PATCH 3/3] object-file: write ".keep" lockfiles during transaction commit Justin Tobler
2026-10-16 6:58 ` Patrick Steinhardt
2026-10-16 19:22 ` Justin Tobler
2026-10-16 21:37 ` [PATCH v2 0/4] object-file: fix ".keep" lockfile ownership in ODB transactions Justin Tobler
2026-10-16 21:37 ` [PATCH v2 1/4] pack-write: make index-pack output comment hash agnostic Justin Tobler
2026-10-16 21:37 ` Justin Tobler [this message]
2026-10-16 21:37 ` [PATCH v2 3/4] object-file: explicitly write ".keep" lockfile Justin Tobler
2026-10-16 21:37 ` [PATCH v2 4/4] object-file: write ".keep" lockfiles during transaction commit Justin Tobler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261016213716.593278-3-jltobler@gmail.com \
--to=jltobler@gmail.com \
--cc=git@vger.kernel.org \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.