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

Re: [PATCH 2/6] commit: fix patch hunk editing with "commit -p -m"

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 6, 2014, 21:25 UTC
Message-ID
<xmqqr46fvx39.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1394117424-29780-3-git-send-email-benoit.pierre@gmail.com>
Benoit Pierre <benoit.pierre@gmail.com> writes:
Show 18 quoted lines
> +int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...)
> +{
> +	const char *hook_env[3] =  { NULL };
> +	char index[PATH_MAX];
> +	va_list args;
> +	int ret;
> +
> +	snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
> +	hook_env[0] = index;
> +
> +	/*
> +	 * Let the hook know that no editor will be launched.
> +	 */
> +	if (!editor_is_used)
> +		hook_env[1] = "GIT_EDITOR=:";
> +
> +	va_start(args, name);
> +	ret = run_hook_v(hook_env, name, args);
Show 11 quoted lines
> diff --git a/run-command.c b/run-command.c
> index 3914d9c..4e9be12 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -760,13 +760,11 @@ char *find_hook(const char *name)
>  	return path;
>  }
>  
> -int run_hook(const char *index_file, const char *name, ...)
> +int run_hook_v(const char *const *env, const char *name, va_list args)
>  {

I think you named it as "foo_v()" for "this takes va_list" in a way similar to the "v" in "execv()", but this also takes environment, so perhaps we want to say "ve" instead?

Other than that, I like it---I admit that I am biased that I essentially did the same earlier but with a _le variant ;-)

> +int run_hook(const char *const *env, const char *name, ...)
> +{

I'd rather not to see this changed in the same commit, so that any other topic in-flight that adds a new call to run_hook() that expects to pass the index file as its first parameter will not be broken.

Name it run_hook_le() (name modelled after execle()), and call it in your change where you add new calls to this function, and add a thin wrapper run_hook() that preserves the traditional "We can pass only the index-file" for new callers we do not even know about on the topics in flight.

Later we can eradicate callers of run_hook() that treats the index-file specially, which was a grave mistake in a public API.

Previous: Benoit PierreNext: Junio C Hamano
Message 6 of 16 in “fix hunk editing with 'commit -p -m'”
  1. 0/6 fix hunk editing with 'commit -p -m'Benoit Pierre, Mar 6, 2014
  2. 1/6 test patch hunk editing with "commit -p -m"Benoit Pierre, Mar 6, 2014
  3. Eric SunshineMar 6, 2014
  4. Junio C HamanoMar 6, 2014
  5. 2/6 commit: fix patch hunk editing with "commit -p -m"Benoit Pierre, Mar 6, 2014
  6. Junio C HamanoMar 6, 2014
  7. Junio C HamanoMar 6, 2014
  8. 3/6 merge: fix GIT_EDITOR override for commit hookBenoit Pierre, Mar 6, 2014
  9. 4/6 merge hook tests: fix and update testsBenoit Pierre, Mar 6, 2014
  10. Eric SunshineMar 6, 2014
  11. 5/6 merge hook tests: fix missing '&&' in testBenoit Pierre, Mar 6, 2014
  12. Junio C HamanoMar 6, 2014
  13. 6/6 merge hook tests: use 'test_must_fail' instead of '!'Benoit Pierre, Mar 6, 2014
  14. Junio C HamanoMar 6, 2014
  15. Junio C HamanoMar 7, 2014
  16. Junio C HamanoMar 6, 2014

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.