From: Justin Tobler <jltobler@gmail.com>
To: git@vger.kernel.org
Cc: ps@pks.im, Justin Tobler <jltobler@gmail.com>
Subject: [PATCH v2 5/7] builtin/receive-pack: report unpack errors via strbuf
Date: Sun, 9 Aug 2026 14:01:04 -0500 [thread overview]
Message-ID: <20260809190106.1565882-6-jltobler@gmail.com> (raw)
In-Reply-To: <20260809190106.1565882-1-jltobler@gmail.com>
When writing packfiles via `unpack()`, error messages are returned
directly by the function. In preparation for `unpack()` logic being
moved behind a generic ODB transaction interface, update the function to
instead write any error messages to a caller provided strbuf and return
a negative value on error. Call sites are updated to use the error
strbuf accordingly.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
builtin/receive-pack.c | 63 ++++++++++++++++++++++++------------------
1 file changed, 36 insertions(+), 27 deletions(-)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 21dab851ad..896439d46d 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -2015,7 +2015,7 @@ static void execute_commands_atomic(struct command *commands,
}
static void execute_commands(struct command *commands,
- const char *unpacker_error,
+ int unpacker_error,
struct shallow_info *si,
struct odb_transaction *transaction,
const struct string_list *push_options)
@@ -2354,8 +2354,8 @@ struct unpack_opts {
int quiet;
};
-static const char *unpack(struct odb_transaction *transaction,
- const struct unpack_opts *opts)
+static int unpack(struct odb_transaction *transaction, struct strbuf *err_msg,
+ const struct unpack_opts *opts)
{
struct pack_header hdr;
const char *hdr_err;
@@ -2367,7 +2367,8 @@ static const char *unpack(struct odb_transaction *transaction,
if (hdr_err) {
if (err_fd > 0)
close(err_fd);
- return hdr_err;
+ strbuf_addstr(err_msg, hdr_err);
+ return -1;
}
if (opts->shallow_file) {
@@ -2392,8 +2393,10 @@ static const char *unpack(struct odb_transaction *transaction,
child.err = err_fd;
child.git_cmd = 1;
status = run_command(&child);
- if (status)
- return "unpack-objects abnormal exit";
+ if (status) {
+ strbuf_addstr(err_msg, "unpack-objects abnormal exit");
+ return -1;
+ }
} else {
char hostname[HOST_NAME_MAX + 1];
char *lockfile;
@@ -2424,8 +2427,10 @@ static const char *unpack(struct odb_transaction *transaction,
child.err = err_fd;
child.git_cmd = 1;
status = start_command(&child);
- if (status)
- return "index-pack fork failed";
+ if (status) {
+ strbuf_addstr(err_msg, "index-pack fork failed");
+ return -1;
+ }
lockfile = index_pack_lockfile(the_repository, child.out, NULL);
if (lockfile) {
@@ -2435,15 +2440,18 @@ static const char *unpack(struct odb_transaction *transaction,
close(child.out);
status = finish_command(&child);
- if (status)
- return "index-pack abnormal exit";
+ if (status) {
+ strbuf_addstr(err_msg, "index-pack abnormal exit");
+ return -1;
+ }
odb_reprepare(the_repository->objects);
}
- return NULL;
+ return 0;
}
-static const char *unpack_with_sideband(struct odb_transaction *transaction,
- const char *shallow_file)
+static int unpack_with_sideband(struct odb_transaction *transaction,
+ const char *shallow_file,
+ struct strbuf *err_msg)
{
struct unpack_opts opts = {
.fsck_objects = (receive_fsck_objects >= 0
@@ -2458,20 +2466,20 @@ static const char *unpack_with_sideband(struct odb_transaction *transaction,
.quiet = quiet,
};
struct async muxer;
- const char *ret;
+ int ret;
if (!use_sideband)
- return unpack(transaction, &opts);
+ return unpack(transaction, err_msg, &opts);
use_keepalive = KEEPALIVE_AFTER_NUL;
memset(&muxer, 0, sizeof(muxer));
muxer.proc = copy_to_sideband;
muxer.in = -1;
if (start_async(&muxer))
- return NULL;
+ return 0;
opts.err_fd = muxer.in;
- ret = unpack(transaction, &opts);
+ ret = unpack(transaction, err_msg, &opts);
finish_async(&muxer);
return ret;
@@ -2560,13 +2568,13 @@ static void update_shallow_info(struct command *commands,
free(ref_status);
}
-static void report(struct command *commands, const char *unpack_status)
+static void report(struct command *commands, const struct strbuf *unpack_status)
{
struct command *cmd;
struct strbuf buf = STRBUF_INIT;
packet_buf_write(&buf, "unpack %s\n",
- unpack_status ? unpack_status : "ok");
+ unpack_status->len ? unpack_status->buf : "ok");
for (cmd = commands; cmd; cmd = cmd->next) {
if (!cmd->error_string)
packet_buf_write(&buf, "ok %s\n",
@@ -2584,14 +2592,14 @@ static void report(struct command *commands, const char *unpack_status)
strbuf_release(&buf);
}
-static void report_v2(struct command *commands, const char *unpack_status)
+static void report_v2(struct command *commands, const struct strbuf *unpack_status)
{
struct command *cmd;
struct strbuf buf = STRBUF_INIT;
struct ref_push_report *report;
packet_buf_write(&buf, "unpack %s\n",
- unpack_status ? unpack_status : "ok");
+ unpack_status->len ? unpack_status->buf : "ok");
for (cmd = commands; cmd; cmd = cmd->next) {
int count = 0;
@@ -2715,8 +2723,8 @@ int cmd_receive_pack(int argc,
PACKET_READ_DIE_ON_ERR_PACKET);
if ((commands = read_head_info(&reader, &shallow))) {
- const char *unpack_status = NULL;
struct string_list push_options = STRING_LIST_INIT_DUP;
+ struct strbuf unpack_status = STRBUF_INIT;
if (use_push_options)
read_push_options(&reader, &push_options);
@@ -2736,22 +2744,22 @@ int cmd_receive_pack(int argc,
alt_shallow_file = setup_temporary_shallow(si.shallow);
if (odb_transaction_begin(the_repository->objects, &transaction, ODB_TRANSACTION_RECEIVE))
- unpack_status = "unable to start object transaction";
+ strbuf_addstr(&unpack_status, "unable to start object transaction");
else
- unpack_status = unpack_with_sideband(transaction, alt_shallow_file);
+ unpack_with_sideband(transaction, alt_shallow_file, &unpack_status);
update_shallow_info(commands, &si, &ref, alt_shallow_file);
}
use_keepalive = KEEPALIVE_ALWAYS;
- execute_commands(commands, unpack_status, &si, transaction,
+ execute_commands(commands, !!unpack_status.len, &si, transaction,
&push_options);
odb_transaction_finalize(transaction);
delete_tempfile(&pack_lockfile);
sigchain_push(SIGPIPE, SIG_IGN);
if (report_status_v2)
- report_v2(commands, unpack_status);
+ report_v2(commands, &unpack_status);
else if (report_status)
- report(commands, unpack_status);
+ report(commands, &unpack_status);
sigchain_pop(SIGPIPE);
run_receive_hook(commands, "post-receive", 1, NULL,
&push_options);
@@ -2776,6 +2784,7 @@ int cmd_receive_pack(int argc,
if (auto_update_server_info)
update_server_info(the_repository, 0);
clear_shallow_info(&si);
+ strbuf_release(&unpack_status);
}
if (use_sideband)
packet_flush(1);
--
2.55.0.424.g13c7afec21
next prev parent reply other threads:[~2026-08-09 19:01 UTC|newest]
Thread overview: 25+ 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-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-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-09 19:01 ` [PATCH v2 4/7] builtin/receive-pack: lift global state out of unpack() Justin Tobler
2026-08-09 19:01 ` Justin Tobler [this message]
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
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=20260809190106.1565882-6-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.