receive-pack: simplify run_update_post_hook()

Instead of counting the arguments to see if there are any and then building the full command use a single loop and add the hook command just before the first argument. This reduces duplication and overall code size. Signed-off-by: Rene Scharfe <l.s.r@web.de> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Mar 17, 2017 at 23:02 UTC dce96c41f9d11280ba25ca3927f3e627f03eaf86
1 file changed +5 -8
builtin/receive-pack.c
+5 -8
@@ -1118,25 +1118,22 @@ static const char *update(struct command *cmd, struct shallow_info *si)
1118 static void run_update_post_hook(struct command *commands)
1119 {
1120 struct command *cmd;
1121 - int argc;
1121 struct child_process proc = CHILD_PROCESS_INIT;
1122 const char *hook;
1123
1124 hook = find_hook("post-update");
1126 - for (argc = 0, cmd = commands; cmd; cmd = cmd->next) {
1127 - if (cmd->error_string || cmd->did_not_exist)
1128 - continue;
1129 - argc++;
1130 - }
1131 - if (!argc || !hook)
1125 + if (!hook)
1126 return;
1127
1134 - argv_array_push(&proc.args, hook);
1128 for (cmd = commands; cmd; cmd = cmd->next) {
1129 if (cmd->error_string || cmd->did_not_exist)
1130 continue;
1131 + if (!proc.args.argc)
1132 + argv_array_push(&proc.args, hook);
1133 argv_array_push(&proc.args, cmd->ref_name);
1134 }
1135 + if (!proc.args.argc)
1136 + return;
1137
1138 proc.no_stdin = 1;
1139 proc.stdout_to_stderr = 1;