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

[PATCH/RFC 7/7] receive-pack: remove unnecessary run_status report

From
Johannes Sixt <j6t@kdbg.org>
Date
Jul 4, 2009, 19:26 UTC
Message-ID
<bc993d449ea426dfdbf6feb76779d98944a8b29a.1246734159.git.j6t@kdbg.org>
In-Reply-To
<87ce2ffef09004ca19acd491b9374283f06c98c2.1246734159.git.j6t@kdbg.org>

The function run_status was used to report failures after a hook was run. By now, the only thing that the function itself reported was the exit code of the hook (if it was non-zero). But this is redundant because it can be expected that the hook itself will have reported a suitable error.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 builtin-receive-pack.c |   20 ++++----------------
 1 files changed, 4 insertions(+), 16 deletions(-)
diff --git a/builtin-receive-pack.c b/builtin-receive-pack.c
index c85507b..b771fe9 100644
--- a/builtin-receive-pack.c
+++ b/builtin-receive-pack.c
@@ -123,13 +123,6 @@ static struct command *commands;
 static const char pre_receive_hook[] = "hooks/pre-receive";
 static const char post_receive_hook[] = "hooks/post-receive";
 
-static int run_status(int code, const char *cmd_name)
-{
-	if (code > 0)
-		error("%s exited with error code %d", cmd_name, code);
-	return code;
-}
-
 static int run_receive_hook(const char *hook_name)
 {
 	static char buf[sizeof(commands->old_sha1) * 2 + PATH_MAX + 4];
@@ -156,7 +149,7 @@ static int run_receive_hook(const char *hook_name)
 
 	code = start_command(&proc);
 	if (code)
-		return run_status(code, hook_name);
+		return code;
 	for (cmd = commands; cmd; cmd = cmd->next) {
 		if (!cmd->error_string) {
 			size_t n = snprintf(buf, sizeof(buf), "%s %s %s\n",
@@ -168,7 +161,7 @@ static int run_receive_hook(const char *hook_name)
 		}
 	}
 	close(proc.in);
-	return run_status(finish_command(&proc), hook_name);
+	return finish_command(&proc);
 }
 
 static int run_update_hook(struct command *cmd)
@@ -185,9 +178,8 @@ static int run_update_hook(struct command *cmd)
 	argv[3] = sha1_to_hex(cmd->new_sha1);
 	argv[4] = NULL;
 
-	return run_status(run_command_v_opt(argv, RUN_COMMAND_NO_STDIN |
-					RUN_COMMAND_STDOUT_TO_STDERR),
-			update_hook);
+	return run_command_v_opt(argv, RUN_COMMAND_NO_STDIN |
+					RUN_COMMAND_STDOUT_TO_STDERR);
 }
 
 static int is_ref_checked_out(const char *ref)
@@ -401,7 +393,6 @@ static void run_update_post_hook(struct command *cmd)
 	argv[argc] = NULL;
 	status = run_command_v_opt(argv, RUN_COMMAND_NO_STDIN
 			| RUN_COMMAND_STDOUT_TO_STDERR);
-	run_status(status, update_post_hook);
 }
 
 static void execute_commands(const char *unpacker_error)
@@ -519,7 +510,6 @@ static const char *unpack(void)
 		code = run_command_v_opt(unpacker, RUN_GIT_CMD);
 		if (!code)
 			return NULL;
-		run_status(code, unpacker[0]);
 		return "unpack-objects abnormal exit";
 	} else {
 		const char *keeper[7];
@@ -545,7 +535,6 @@ static const char *unpack(void)
 		ip.git_cmd = 1;
 		status = start_command(&ip);
 		if (status) {
-			run_status(status, keeper[0]);
 			return "index-pack fork failed";
 		}
 		pack_lockfile = index_pack_lockfile(ip.out);
@@ -555,7 +544,6 @@ static const char *unpack(void)
 			reprepare_packed_git();
 			return NULL;
 		}
-		run_status(status, keeper[0]);
 		return "index-pack abnormal exit";
 	}
 }
-- 
1.6.3.17.g1665f
Previous: Johannes SixtNext: Johannes Sixt
Message 8 of 12 in “rework run_command error reporting”
  1. 0/7 rework run_command error reportingJohannes Sixt, Jul 4, 2009
  2. 1/7 Truncate result of run_command that is used in exit() to lowest 8 bitsJohannes Sixt, Jul 4, 2009
  3. 2/7 MinGW: simplify waitpid() emulation macrosJohannes Sixt, Jul 4, 2009
  4. 3/7 run_command: return exit code as positive valueJohannes Sixt, Jul 4, 2009
  5. 4/7 run_command: report system call errors instead of returning error codesJohannes Sixt, Jul 4, 2009
  6. 5/7 run_command: encode deadly signal number in the return valueJohannes Sixt, Jul 4, 2009
  7. 6/7 run_command: report failure to execute the program, but optionally don'tJohannes Sixt, Jul 4, 2009
  8. 7/7 receive-pack: remove unnecessary run_status reportJohannes Sixt, Jul 4, 2009
  9. Johannes SixtJul 5, 2009
  10. Junio C HamanoJul 5, 2009
  11. Johannes SixtJul 6, 2009
  12. 1/7 MinGW: truncate exit()'s argument to lowest 8 bitsJohannes Sixt, Jul 5, 2009

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.