Re: [PATCH 1/4] git-commit: support variable number of hook arguments
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Feb 4, 2008, 16:43 UTC
- Message-ID
- <alpine.LSU.1.00.0802041637460.7372@racer.site>
- In-Reply-To
- <2885c7896ba72adee6bc5c9e2210a8881904f601.1200933409.git.bonzini@gnu.org>
Hi,
On Mon, 21 Jan 2008, Paolo Bonzini wrote:
Show 12 quoted lines
> +static int run_hook(const char *index_file, const char *name, ...)
> +{
> + struct child_process hook;
> + const char *argv[10], *env[2];
> + char index[PATH_MAX];
> + va_list args;
> + int i;
> +
> + va_start(args, name);
> + argv[0] = git_path("hooks/%s", name);
> + i = 0;
> + do {Here, an
if (++i >= ARRAY_SIZE(argv))
die ("run_hook(): too many arguments");is missing. Even nicer, you could have
int argc = 1; char **argv = malloc(sizeof(*argv) * 2);
and
if (++i >= argc) argc = ALLOC_GROW(argv, i + 1, argc);
in the loop. Of course, you would have to change the "++i" to "i" in this line:
> + argv[++i] = va_arg(args, const char *);
Ciao, Dscho