summaryrefslogtreecommitdiff
path: root/builtin/receive-pack.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-03-17 22:02:13 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-03-18 17:13:09 (GMT)
commitdce96c41f9d11280ba25ca3927f3e627f03eaf86 (patch)
tree5f004ab609d339d995ac8dc77e771c0adb436b17 /builtin/receive-pack.c
parentc3808ca6982b0ad7ee9b87eca9b50b9a24ec08b0 (diff)
downloadgit-dce96c41f9d11280ba25ca3927f3e627f03eaf86.zip
git-dce96c41f9d11280ba25ca3927f3e627f03eaf86.tar.gz
git-dce96c41f9d11280ba25ca3927f3e627f03eaf86.tar.bz2
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>
Diffstat (limited to 'builtin/receive-pack.c')
-rw-r--r--builtin/receive-pack.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 011db00..a5279e9 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1118,25 +1118,22 @@ static const char *update(struct command *cmd, struct shallow_info *si)
static void run_update_post_hook(struct command *commands)
{
struct command *cmd;
- int argc;
struct child_process proc = CHILD_PROCESS_INIT;
const char *hook;
hook = find_hook("post-update");
- for (argc = 0, cmd = commands; cmd; cmd = cmd->next) {
- if (cmd->error_string || cmd->did_not_exist)
- continue;
- argc++;
- }
- if (!argc || !hook)
+ if (!hook)
return;
- argv_array_push(&proc.args, hook);
for (cmd = commands; cmd; cmd = cmd->next) {
if (cmd->error_string || cmd->did_not_exist)
continue;
+ if (!proc.args.argc)
+ argv_array_push(&proc.args, hook);
argv_array_push(&proc.args, cmd->ref_name);
}
+ if (!proc.args.argc)
+ return;
proc.no_stdin = 1;
proc.stdout_to_stderr = 1;