git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

Previous: Paolo BonziniNext: Junio C Hamano
Message 3 of 13 in “git-commit: add a prepare-commit-msg hook”
  1. git-commit: add a prepare-commit-msg hookPaolo Bonzini, Jan 21, 2008
  2. 1/4 git-commit: support variable number of hook argumentsPaolo Bonzini, Jan 21, 2008
  3. Johannes SchindelinFeb 4, 2008
  4. Junio C HamanoFeb 5, 2008
  5. 2/4 git-commit: set GIT_EDITOR=: if editor will not be launchedPaolo Bonzini, Jan 21, 2008
  6. 4/4 git-commit: add a prepare-commit-msg hookPaolo Bonzini, Jan 21, 2008
  7. Junio C HamanoFeb 5, 2008
  8. 3/4 git-commit: Refactor creation of log message.Paolo Bonzini, Jan 21, 2008
  9. Johannes SchindelinFeb 4, 2008
  10. Paolo BonziniFeb 4, 2008
  11. Junio C HamanoFeb 5, 2008
  12. Junio C HamanoFeb 5, 2008
  13. Paolo BonziniFeb 5, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.