{"thread":{"id":"7182","subject":"[PATCH 7/8] Split back out update_hook handling in receive-pack","startedAt":"2007-03-10T08:28:13Z","lastAt":"2007-03-10T08:28:13Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"36740","messageId":"20070310082813.GG4133@spearce.org","threadId":"7182","inReplyTo":null,"subject":"[PATCH 7/8] Split back out update_hook handling in receive-pack","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-03-10T08:28:13Z","receivedAt":"2007-03-10T08:28:13Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Since we have decided to change the calling conventions for the\npre-receive and post-receive hooks to take the ref data on stdin\nrather than on the command line we cannot use the same logic to\ninvoke the update hook anymore.\n\nSo we take a small step backwards towards what we used to have,\nand create a specialized function for executing just the update\nhook.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n receive-pack.c |   26 ++++++++++++++++++++++++--\n 1 files changed, 24 insertions(+), 2 deletions(-)\n\ndiff --git a/receive-pack.c b/receive-pack.c\nindex e147076..4d7170f 100644\n--- a/receive-pack.c\n+++ b/receive-pack.c\n@@ -67,7 +67,6 @@ struct command {\n \n static struct command *commands;\n \n-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@@ -134,6 +133,29 @@ static int run_hook(const char *hook_name,\n \treturn hook_status(code, hook_name);\n }\n \n+static int run_update_hook(struct command *cmd)\n+{\n+\tstatic const char update_hook[] = \"hooks/update\";\n+\tstruct child_process proc;\n+\tconst char *argv[5];\n+\n+\tif (access(update_hook, X_OK) < 0)\n+\t\treturn 0;\n+\n+\targv[0] = update_hook;\n+\targv[1] = cmd->ref_name;\n+\targv[2] = sha1_to_hex(cmd->old_sha1);\n+\targv[3] = sha1_to_hex(cmd->new_sha1);\n+\targv[4] = NULL;\n+\n+\tmemset(&proc, 0, sizeof(proc));\n+\tproc.argv = argv;\n+\tproc.no_stdin = 1;\n+\tproc.stdout_to_stderr = 1;\n+\n+\treturn hook_status(run_command(&proc), update_hook);\n+}\n+\n static const char *update(struct command *cmd)\n {\n \tconst char *name = cmd->ref_name;\n@@ -170,7 +192,7 @@ static const char *update(struct command *cmd)\n \t\t\treturn \"non-fast forward\";\n \t\t}\n \t}\n-\tif (run_hook(update_hook, cmd, 1)) {\n+\tif (run_update_hook(cmd)) {\n \t\terror(\"hook declined to update %s\", name);\n \t\treturn \"hook declined\";\n \t}\n-- \n1.5.0.3.942.g299f\n"}]}