Skip to content

Commit 14e6298

Browse files
sbeyergitster
authored andcommitted
run_hook(): allow more than 9 hook arguments
This is done using the ALLOC_GROW macro. Signed-off-by: Stephan Beyer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cf94ca8 commit 14e6298

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Documentation/technical/api-run-command.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Functions
5858
The first argument is a pathname to an index file, or NULL
5959
if the hook uses the default index file or no index is needed.
6060
The second argument is the name of the hook.
61-
The further arguments (up to 9) correspond to the hook arguments.
61+
The further arguments correspond to the hook arguments.
6262
The last argument has to be NULL to terminate the arguments list.
6363
If the hook does not exist or is not executable, the return
6464
value will be zero.

run-command.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,23 +346,22 @@ int finish_async(struct async *async)
346346
int run_hook(const char *index_file, const char *name, ...)
347347
{
348348
struct child_process hook;
349-
const char *argv[10], *env[2];
349+
const char **argv = NULL, *env[2];
350350
char index[PATH_MAX];
351351
va_list args;
352352
int ret;
353-
int i;
353+
size_t i = 0, alloc = 0;
354354

355355
if (access(git_path("hooks/%s", name), X_OK) < 0)
356356
return 0;
357357

358358
va_start(args, name);
359-
argv[0] = git_path("hooks/%s", name);
360-
i = 0;
361-
do {
362-
if (++i >= ARRAY_SIZE(argv))
363-
die("run_hook(): too many arguments");
364-
argv[i] = va_arg(args, const char *);
365-
} while (argv[i]);
359+
ALLOC_GROW(argv, i + 1, alloc);
360+
argv[i++] = git_path("hooks/%s", name);
361+
while (argv[i-1]) {
362+
ALLOC_GROW(argv, i + 1, alloc);
363+
argv[i++] = va_arg(args, const char *);
364+
}
366365
va_end(args);
367366

368367
memset(&hook, 0, sizeof(hook));
@@ -377,6 +376,7 @@ int run_hook(const char *index_file, const char *name, ...)
377376
}
378377

379378
ret = start_command(&hook);
379+
free(argv);
380380
if (ret) {
381381
warning("Could not spawn %s", argv[0]);
382382
return ret;

0 commit comments

Comments
 (0)