Refactor run_command error handling in receive-pack
I'm pulling the error handling used to decode the result of run_command up into a new function so that I can reuse it. No changes, just a simple code movement. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Shawn O. Pearce committed
Mar 10, 2007 at 03:28 UTC
6c319a22e47e6b49d799f5893aeac92e723a5e6f
1 file changed
+24
-19
receive-pack.c
+24
-19
@@ -71,6 +71,29 @@ static const char update_hook[] = "hooks/update";
71
static const char pre_receive_hook[] = "hooks/pre-receive";
72
static const char post_receive_hook[] = "hooks/post-receive";
73
74
+static int hook_status(int code, const char *hook_name)
75
+{
76
+ switch (code) {
77
+ case 0:
78
+ return 0;
79
+ case -ERR_RUN_COMMAND_FORK:
80
+ return error("hook fork failed");
81
+ case -ERR_RUN_COMMAND_EXEC:
82
+ return error("hook execute failed");
83
+ case -ERR_RUN_COMMAND_WAITPID:
84
+ return error("waitpid failed");
85
+ case -ERR_RUN_COMMAND_WAITPID_WRONG_PID:
86
+ return error("waitpid is confused");
87
+ case -ERR_RUN_COMMAND_WAITPID_SIGNAL:
88
+ return error("%s died of signal", hook_name);
89
+ case -ERR_RUN_COMMAND_WAITPID_NOEXIT:
90
+ return error("%s died strangely", hook_name);
91
+ default:
92
+ error("%s exited with error code %d", hook_name, -code);
93
+ return -code;
94
+ }
95
+}
96
+
97
static int run_hook(const char *hook_name,
98
struct command *first_cmd,
99
int single)
@@ -108,25 +131,7 @@ static int run_hook(const char *hook_name,
131
free((char*)argv[argc]);
132
free(argv);
133
111
- switch (code) {
112
- case 0:
113
- return 0;
114
- case -ERR_RUN_COMMAND_FORK:
115
- return error("hook fork failed");
116
- case -ERR_RUN_COMMAND_EXEC:
117
- return error("hook execute failed");
118
- case -ERR_RUN_COMMAND_WAITPID:
119
- return error("waitpid failed");
120
- case -ERR_RUN_COMMAND_WAITPID_WRONG_PID:
121
- return error("waitpid is confused");
122
- case -ERR_RUN_COMMAND_WAITPID_SIGNAL:
123
- return error("%s died of signal", hook_name);
124
- case -ERR_RUN_COMMAND_WAITPID_NOEXIT:
125
- return error("%s died strangely", hook_name);
126
- default:
127
- error("%s exited with error code %d", hook_name, -code);
128
- return -code;
129
- }
134
+ return hook_status(code, hook_name);
135
}
136
137
static const char *update(struct command *cmd)