From: Justin Tobler <jltobler@gmail.com>
To: git@vger.kernel.org
Cc: ps@pks.im, gitster@pobox.com, Justin Tobler <jltobler@gmail.com>
Subject: [PATCH v5 5/9] builtin/receive-pack: lift global state out of unpack()
Date: Thu, 20 Aug 2026 18:49:36 -0500 [thread overview]
Message-ID: <20260820234940.894624-6-jltobler@gmail.com> (raw)
In-Reply-To: <20260820234940.894624-1-jltobler@gmail.com>
In git-receive-pack(1), writing the packfile to the transaction is
handled via `unpack()` which relies on global variables to decide how to
invoke the underlying git-index-pack(1) or git-unpack-objects(1) child
processes. In a subsequent commit, the `unpack()` logic is moved behind
a generic ODB transaction interface to handle writing packfiles and thus
can no longer rely on these globals.
Lift the global state out of `unpack()` by instead storing this state in
a `struct unpack_opts` that gets passed to the function explicitly.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
builtin/receive-pack.c | 63 +++++++++++++++++++++++++++---------------
1 file changed, 41 insertions(+), 22 deletions(-)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 971dc3f52e..f062b93b8d 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -2330,18 +2330,24 @@ static unsigned int get_unpack_limit(struct repository *repo)
return limit;
}
+struct unpack_opts {
+ const char *fsck_msg_types;
+ const char *shallow_file;
+ off_t max_input_size;
+ int fsck_objects;
+ int reject_thin;
+ int err_fd;
+ int quiet;
+};
+
static const char *unpack(struct odb_transaction *transaction,
- const char *shallow_file, int err_fd)
+ const struct unpack_opts *opts)
{
struct pack_header hdr;
const char *hdr_err;
int status;
struct child_process child = CHILD_PROCESS_INIT;
- int fsck_objects = (receive_fsck_objects >= 0
- ? receive_fsck_objects
- : transfer_fsck_objects >= 0
- ? transfer_fsck_objects
- : 0);
+ int err_fd = opts->err_fd;
hdr_err = parse_pack_header(&hdr);
if (hdr_err) {
@@ -2350,9 +2356,9 @@ static const char *unpack(struct odb_transaction *transaction,
return hdr_err;
}
- if (shallow_file) {
+ if (opts->shallow_file) {
strvec_push(&child.args, "--shallow-file");
- strvec_push(&child.args, shallow_file);
+ strvec_push(&child.args, opts->shallow_file);
}
odb_transaction_env(transaction, &child.env);
@@ -2360,14 +2366,14 @@ static const char *unpack(struct odb_transaction *transaction,
if (ntohl(hdr.hdr_entries) < get_unpack_limit(the_repository)) {
strvec_push(&child.args, "unpack-objects");
push_header_arg(&child.args, &hdr);
- if (quiet)
+ if (opts->quiet)
strvec_push(&child.args, "-q");
- if (fsck_objects)
+ if (opts->fsck_objects)
strvec_pushf(&child.args, "--strict%s",
- fsck_msg_types.buf);
- if (max_input_size)
+ opts->fsck_msg_types);
+ if (opts->max_input_size)
strvec_pushf(&child.args, "--max-input-size=%"PRIuMAX,
- (uintmax_t)max_input_size);
+ (uintmax_t)opts->max_input_size);
child.no_stdout = 1;
child.err = err_fd;
child.git_cmd = 1;
@@ -2388,18 +2394,18 @@ static const char *unpack(struct odb_transaction *transaction,
(uintmax_t)getpid(),
hostname);
- if (!quiet && err_fd)
+ if (!opts->quiet && err_fd)
strvec_push(&child.args, "--show-resolving-progress");
- if (use_sideband)
+ if (err_fd)
strvec_push(&child.args, "--report-end-of-input");
- if (fsck_objects)
+ if (opts->fsck_objects)
strvec_pushf(&child.args, "--strict%s",
- fsck_msg_types.buf);
- if (!reject_thin)
+ opts->fsck_msg_types);
+ if (!opts->reject_thin)
strvec_push(&child.args, "--fix-thin");
- if (max_input_size)
+ if (opts->max_input_size)
strvec_pushf(&child.args, "--max-input-size=%"PRIuMAX,
- (uintmax_t)max_input_size);
+ (uintmax_t)opts->max_input_size);
child.out = -1;
child.err = err_fd;
child.git_cmd = 1;
@@ -2431,11 +2437,23 @@ static const char *unpack(struct odb_transaction *transaction,
static const char *unpack_with_sideband(struct odb_transaction *transaction,
const char *shallow_file)
{
+ struct unpack_opts opts = {
+ .fsck_objects = (receive_fsck_objects >= 0
+ ? receive_fsck_objects
+ : transfer_fsck_objects >= 0
+ ? transfer_fsck_objects
+ : 0),
+ .fsck_msg_types = fsck_msg_types.buf,
+ .max_input_size = max_input_size,
+ .shallow_file = shallow_file,
+ .reject_thin = reject_thin,
+ .quiet = quiet,
+ };
struct async muxer;
const char *ret;
if (!use_sideband)
- return unpack(transaction, shallow_file, 0);
+ return unpack(transaction, &opts);
use_keepalive = KEEPALIVE_AFTER_NUL;
memset(&muxer, 0, sizeof(muxer));
@@ -2444,7 +2462,8 @@ static const char *unpack_with_sideband(struct odb_transaction *transaction,
if (start_async(&muxer))
return NULL;
- ret = unpack(transaction, shallow_file, muxer.in);
+ opts.err_fd = muxer.in;
+ ret = unpack(transaction, &opts);
finish_async(&muxer);
return ret;
--
2.55.0.424.g13c7afec21
next prev parent reply other threads:[~2026-08-20 23:49 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 21:38 [PATCH 0/6] builtin/receive-pack: support pluggable packfile writes Justin Tobler
2026-08-06 21:38 ` [PATCH 1/6] odb/transaction: add transaction release interface Justin Tobler
2026-08-07 7:03 ` Patrick Steinhardt
2026-08-07 15:11 ` Justin Tobler
2026-08-06 21:38 ` [PATCH 2/6] builtin/receive-pack: pass shallow file explicitly Justin Tobler
2026-08-07 7:03 ` Patrick Steinhardt
2026-08-06 21:38 ` [PATCH 3/6] builtin/receive-pack: lift global state out of unpack() Justin Tobler
2026-08-07 7:03 ` Patrick Steinhardt
2026-08-07 15:33 ` Justin Tobler
2026-08-06 21:38 ` [PATCH 4/6] builtin/receive-pack: report unpack errors via strbuf Justin Tobler
2026-08-07 7:03 ` Patrick Steinhardt
2026-08-07 15:36 ` Justin Tobler
2026-08-09 19:00 ` Justin Tobler
2026-08-10 5:15 ` Patrick Steinhardt
2026-08-06 21:38 ` [PATCH 5/6] builtin/receive-pack: explicitly pass packfile fd Justin Tobler
2026-08-06 21:38 ` [PATCH 6/6] odb/transaction: add transaction interface to write packfiles Justin Tobler
2026-08-07 7:03 ` Patrick Steinhardt
2026-08-07 16:01 ` Justin Tobler
2026-08-09 19:00 ` [PATCH v2 0/7] builtin/receive-pack: support pluggable packfile writes Justin Tobler
2026-08-09 19:01 ` [PATCH v2 1/7] odb/transaction: add transaction finalize interface Justin Tobler
2026-08-10 3:38 ` Junio C Hamano
2026-08-10 19:10 ` Justin Tobler
2026-08-09 19:01 ` [PATCH v2 2/7] builtin/receive-pack: pass shallow file explicitly Justin Tobler
2026-08-09 19:01 ` [PATCH v2 3/7] builtin/receive-pack: read unpack limit config lazily Justin Tobler
2026-08-10 5:15 ` Patrick Steinhardt
2026-08-10 15:42 ` Justin Tobler
2026-08-10 17:54 ` Junio C Hamano
2026-08-10 19:16 ` Justin Tobler
2026-08-09 19:01 ` [PATCH v2 4/7] builtin/receive-pack: lift global state out of unpack() Justin Tobler
2026-08-09 19:01 ` [PATCH v2 5/7] builtin/receive-pack: report unpack errors via strbuf Justin Tobler
2026-08-09 19:01 ` [PATCH v2 6/7] builtin/receive-pack: explicitly pass packfile fd Justin Tobler
2026-08-09 19:01 ` [PATCH v2 7/7] odb/transaction: add transaction interface to write packfiles Justin Tobler
2026-08-10 1:54 ` Junio C Hamano
2026-08-10 19:29 ` Justin Tobler
2026-08-10 4:02 ` Junio C Hamano
2026-08-10 19:54 ` Justin Tobler
2026-08-11 17:54 ` [PATCH v3 0/9] builtin/receive-pack: support pluggable packfile writes Justin Tobler
2026-08-11 17:54 ` [PATCH v3 1/9] builtin/receive-pack: properly clean up keep files Justin Tobler
2026-08-12 6:07 ` Patrick Steinhardt
2026-08-13 21:45 ` Justin Tobler
2026-08-14 7:46 ` Patrick Steinhardt
2026-08-11 17:54 ` [PATCH v3 2/9] odb/transaction: add transaction finalize interface Justin Tobler
2026-08-12 6:07 ` Patrick Steinhardt
2026-08-11 17:54 ` [PATCH v3 3/9] builtin/receive-pack: pass shallow file explicitly Justin Tobler
2026-08-11 17:54 ` [PATCH v3 4/9] builtin/receive-pack: read unpack limit config lazily Justin Tobler
2026-08-11 17:54 ` [PATCH v3 5/9] builtin/receive-pack: lift global state out of unpack() Justin Tobler
2026-08-11 17:54 ` [PATCH v3 6/9] builtin/receive-pack: report unpack errors via strbuf Justin Tobler
2026-08-11 17:54 ` [PATCH v3 7/9] builtin/receive-pack: explicitly pass packfile fd Justin Tobler
2026-08-11 17:54 ` [PATCH v3 8/9] odb: return temporary ODB source when set Justin Tobler
2026-08-12 6:07 ` Patrick Steinhardt
2026-08-11 17:54 ` [PATCH v3 9/9] odb/transaction: add transaction interface to write packfiles Justin Tobler
2026-08-14 8:51 ` Patrick Steinhardt
2026-08-14 13:40 ` Justin Tobler
2026-08-17 5:17 ` Patrick Steinhardt
2026-08-19 21:53 ` [PATCH v4 0/9] builtin/receive-pack: support pluggable packfile writes Justin Tobler
2026-08-19 21:53 ` [PATCH v4 1/9] builtin/receive-pack: properly clean up keep files Justin Tobler
2026-08-20 6:46 ` Patrick Steinhardt
2026-08-20 21:33 ` Justin Tobler
2026-08-19 21:53 ` [PATCH v4 2/9] odb/transaction: add transaction finalize interface Justin Tobler
2026-08-20 6:46 ` Patrick Steinhardt
2026-08-19 21:53 ` [PATCH v4 3/9] builtin/receive-pack: pass shallow file explicitly Justin Tobler
2026-08-19 21:53 ` [PATCH v4 4/9] builtin/receive-pack: read unpack limit config lazily Justin Tobler
2026-08-19 21:53 ` [PATCH v4 5/9] builtin/receive-pack: lift global state out of unpack() Justin Tobler
2026-08-19 21:53 ` [PATCH v4 6/9] builtin/receive-pack: report unpack errors via strbuf Justin Tobler
2026-08-19 21:53 ` [PATCH v4 7/9] builtin/receive-pack: explicitly pass packfile fd Justin Tobler
2026-08-19 21:53 ` [PATCH v4 8/9] odb: return temporary ODB source when set Justin Tobler
2026-08-19 21:53 ` [PATCH v4 9/9] odb/transaction: add transaction interface to write packfiles Justin Tobler
2026-08-20 6:46 ` Patrick Steinhardt
2026-08-20 23:49 ` [PATCH v5 0/9] builtin/receive-pack: support pluggable packfile writes Justin Tobler
2026-08-20 23:49 ` [PATCH v5 1/9] builtin/receive-pack: properly clean up keep files Justin Tobler
2026-08-20 23:49 ` [PATCH v5 2/9] odb/transaction: add transaction finalize interface Justin Tobler
2026-08-20 23:49 ` [PATCH v5 3/9] builtin/receive-pack: pass shallow file explicitly Justin Tobler
2026-08-20 23:49 ` [PATCH v5 4/9] builtin/receive-pack: read unpack limit config lazily Justin Tobler
2026-08-20 23:49 ` Justin Tobler [this message]
2026-08-20 23:49 ` [PATCH v5 6/9] builtin/receive-pack: report unpack errors via strbuf Justin Tobler
2026-08-20 23:49 ` [PATCH v5 7/9] builtin/receive-pack: explicitly pass packfile fd Justin Tobler
2026-08-20 23:49 ` [PATCH v5 8/9] odb: return temporary ODB source when set Justin Tobler
2026-08-20 23:49 ` [PATCH v5 9/9] odb/transaction: add transaction interface to write packfiles 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=20260820234940.894624-6-jltobler@gmail.com \
--to=jltobler@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox