git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] object-file: return error on index-pack abnormal exit

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 4, 2026, 23:06 UTC
Message-ID
<xmqq8q38yz5i.fsf@gitster.g>
In-Reply-To
<20261103212410.1389988-3-jltobler@gmail.com>
Justin Tobler <jltobler@gmail.com> writes:
Show 24 quoted lines
> diff --git a/object-file.c b/object-file.c
> index a9800143bd..e04ce0bc11 100644
> --- a/object-file.c
> +++ b/object-file.c
> @@ -1429,8 +1429,7 @@ static int odb_transaction_files_write_pack(struct odb_transaction *base,
>  	struct pack_header hdr;
>  	const char *hdr_err;
>  	int err_fd = opts->err_fd;
> -	int ret = -1;
> -	int status;
> +	int ret;
>  
>  	hdr_err = parse_pack_header(&hdr, pack_fd);
>  	if (hdr_err) {
> @@ -1462,12 +1461,13 @@ static int odb_transaction_files_write_pack(struct odb_transaction *base,
>  		child.in = pack_fd;
>  		child.err = err_fd;
>  		child.git_cmd = 1;
> -		status = run_command(&child);
> -		if (status) {
> +		if (run_command(&child)) {
>  			strbuf_addstr(err_msg, "unpack-objects abnormal exit");
>  			return -1;
>  		}
OK.  A slight simplication that does not change any behaviour.
Show 29 quoted lines
>  	} else {
> +		int report_err;
> +
>  		strvec_pushl(&child.args, "index-pack", "--stdin", NULL);
>  		push_header_arg(&child.args, &hdr);
>  
> @@ -1487,24 +1487,24 @@ static int odb_transaction_files_write_pack(struct odb_transaction *base,
>  		child.in = pack_fd;
>  		child.err = err_fd;
>  		child.git_cmd = 1;
> -		status = start_command(&child);
> -		if (status) {
> +		if (start_command(&child)) {
>  			strbuf_addstr(err_msg, "index-pack fork failed");
>  			return -1;
>  		}
>  
> -		ret = read_index_pack_report(repo, child.out, &pack_name, NULL);
> +		report_err = read_index_pack_report(repo, child.out, &pack_name, NULL);
>  
>  		close(child.out);
>  
> -		status = finish_command(&child);
> -		if (status) {
> +		if (finish_command(&child)) {
>  			strbuf_addstr(err_msg, "index-pack abnormal exit");
> +			ret = -1;
>  			goto out;
>  		}
OK.  A slight simplication that does not change any behaviour again.
Show 6 quoted lines
> -		if (ret) {
> +		if (report_err) {
>  			strbuf_addstr(err_msg, "index-pack failed to report pack name");
> +			ret = -1;
>  			goto out;
>  		}

I guess this also does not change a behaviour? We used to relay the error status returned by read_index_pack_report(), but now we force the error code to an explicit -1.

Personally, I somehow find that the original "unless we positively declare success, default to 'ret = -1', and if we may have detected more specific error, return it back, and reset ret to 0 when we see a success" easier to follow, but that may be subjective preference.

Will queue.  Thanks.
Previous: Justin ToblerNext: Karthik Nayak
Message 5 of 6 in “object-file: small error handling follow-ups”
  1. 0/2 object-file: small error handling follow-upsJustin Tobler, Nov 3, 2026
  2. 1/2 object-file: warn on failed unlinkJustin Tobler, Nov 3, 2026
  3. Junio C HamanoNov 4, 2026
  4. 2/2 object-file: return error on index-pack abnormal exitJustin Tobler, Nov 3, 2026
  5. Junio C HamanoNov 4, 2026
  6. Karthik NayakNov 4, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.