Skip to content

Commit dce96c4

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c3808ca commit dce96c4

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

builtin/receive-pack.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,25 +1118,22 @@ static const char *update(struct command *cmd, struct shallow_info *si)
11181118
static void run_update_post_hook(struct command *commands)
11191119
{
11201120
struct command *cmd;
1121-
int argc;
11221121
struct child_process proc = CHILD_PROCESS_INIT;
11231122
const char *hook;
11241123

11251124
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)
11321126
return;
11331127

1134-
argv_array_push(&proc.args, hook);
11351128
for (cmd = commands; cmd; cmd = cmd->next) {
11361129
if (cmd->error_string || cmd->did_not_exist)
11371130
continue;
1131+
if (!proc.args.argc)
1132+
argv_array_push(&proc.args, hook);
11381133
argv_array_push(&proc.args, cmd->ref_name);
11391134
}
1135+
if (!proc.args.argc)
1136+
return;
11401137

11411138
proc.no_stdin = 1;
11421139
proc.stdout_to_stderr = 1;

0 commit comments

Comments
 (0)