{"thread":{"id":"7181","subject":"[PATCH 6/8] Refactor run_command error handling in receive-pack","startedAt":"2007-03-10T08:28:11Z","lastAt":"2007-03-10T08:28:11Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"36739","messageId":"20070310082811.GF4133@spearce.org","threadId":"7181","inReplyTo":null,"subject":"[PATCH 6/8] Refactor run_command error handling in receive-pack","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-03-10T08:28:11Z","receivedAt":"2007-03-10T08:28:11Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"I'm pulling the error handling used to decode the result of\nrun_command up into a new function so that I can reuse it.\nNo changes, just a simple code movement.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n receive-pack.c |   43 ++++++++++++++++++++++++-------------------\n 1 files changed, 24 insertions(+), 19 deletions(-)\n\ndiff --git a/receive-pack.c b/receive-pack.c\nindex 675c88f..e147076 100644\n--- a/receive-pack.c\n+++ b/receive-pack.c\n@@ -71,6 +71,29 @@ static const char update_hook[] = \"hooks/update\";\n static const char pre_receive_hook[] = \"hooks/pre-receive\";\n static const char post_receive_hook[] = \"hooks/post-receive\";\n \n+static int hook_status(int code, const char *hook_name)\n+{\n+\tswitch (code) {\n+\tcase 0:\n+\t\treturn 0;\n+\tcase -ERR_RUN_COMMAND_FORK:\n+\t\treturn error(\"hook fork failed\");\n+\tcase -ERR_RUN_COMMAND_EXEC:\n+\t\treturn error(\"hook execute failed\");\n+\tcase -ERR_RUN_COMMAND_WAITPID:\n+\t\treturn error(\"waitpid failed\");\n+\tcase -ERR_RUN_COMMAND_WAITPID_WRONG_PID:\n+\t\treturn error(\"waitpid is confused\");\n+\tcase -ERR_RUN_COMMAND_WAITPID_SIGNAL:\n+\t\treturn error(\"%s died of signal\", hook_name);\n+\tcase -ERR_RUN_COMMAND_WAITPID_NOEXIT:\n+\t\treturn error(\"%s died strangely\", hook_name);\n+\tdefault:\n+\t\terror(\"%s exited with error code %d\", hook_name, -code);\n+\t\treturn -code;\n+\t}\n+}\n+\n static int run_hook(const char *hook_name,\n \tstruct command *first_cmd,\n \tint single)\n@@ -108,25 +131,7 @@ static int run_hook(const char *hook_name,\n \t\tfree((char*)argv[argc]);\n \tfree(argv);\n \n-\tswitch (code) {\n-\tcase 0:\n-\t\treturn 0;\n-\tcase -ERR_RUN_COMMAND_FORK:\n-\t\treturn error(\"hook fork failed\");\n-\tcase -ERR_RUN_COMMAND_EXEC:\n-\t\treturn error(\"hook execute failed\");\n-\tcase -ERR_RUN_COMMAND_WAITPID:\n-\t\treturn error(\"waitpid failed\");\n-\tcase -ERR_RUN_COMMAND_WAITPID_WRONG_PID:\n-\t\treturn error(\"waitpid is confused\");\n-\tcase -ERR_RUN_COMMAND_WAITPID_SIGNAL:\n-\t\treturn error(\"%s died of signal\", hook_name);\n-\tcase -ERR_RUN_COMMAND_WAITPID_NOEXIT:\n-\t\treturn error(\"%s died strangely\", hook_name);\n-\tdefault:\n-\t\terror(\"%s exited with error code %d\", hook_name, -code);\n-\t\treturn -code;\n-\t}\n+\treturn hook_status(code, hook_name);\n }\n \n static const char *update(struct command *cmd)\n-- \n1.5.0.3.942.g299f\n"}]}