@matheusbsbs / matheus-bagliano / commits / 1d9e8b56fe
Fork 0

Split back out update_hook handling in receive-pack

Since we have decided to change the calling conventions for the pre-receive and post-receive hooks to take the ref data on stdin rather than on the command line we cannot use the same logic to invoke the update hook anymore. So we take a small step backwards towards what we used to have, and create a specialized function for executing just the update hook. 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 1d9e8b56fe3a0360bf61ce633827af8fa9a7013c
1 file changed +24 -2
receive-pack.c
+24 -2
@@ -67,7 +67,6 @@ struct command {
67
68 static struct command *commands;
69
70 -static const char update_hook[] = "hooks/update";
70 static const char pre_receive_hook[] = "hooks/pre-receive";
71 static const char post_receive_hook[] = "hooks/post-receive";
72
@@ -134,6 +133,29 @@ static int run_hook(const char *hook_name,
133 return hook_status(code, hook_name);
134 }
135
136 +static int run_update_hook(struct command *cmd)
137 +{
138 + static const char update_hook[] = "hooks/update";
139 + struct child_process proc;
140 + const char *argv[5];
141 +
142 + if (access(update_hook, X_OK) < 0)
143 + return 0;
144 +
145 + argv[0] = update_hook;
146 + argv[1] = cmd->ref_name;
147 + argv[2] = sha1_to_hex(cmd->old_sha1);
148 + argv[3] = sha1_to_hex(cmd->new_sha1);
149 + argv[4] = NULL;
150 +
151 + memset(&proc, 0, sizeof(proc));
152 + proc.argv = argv;
153 + proc.no_stdin = 1;
154 + proc.stdout_to_stderr = 1;
155 +
156 + return hook_status(run_command(&proc), update_hook);
157 +}
158 +
159 static const char *update(struct command *cmd)
160 {
161 const char *name = cmd->ref_name;
@@ -170,7 +192,7 @@ static const char *update(struct command *cmd)
192 return "non-fast forward";
193 }
194 }
173 - if (run_hook(update_hook, cmd, 1)) {
195 + if (run_update_hook(cmd)) {
196 error("hook declined to update %s", name);
197 return "hook declined";
198 }