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

Re: [RFC/PATCH] commit: update the index after running the pre-commit hook

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Aug 18, 2010, 22:51 UTC
Message-ID
<20100818225130.GC2346@burratino>
In-Reply-To
<1282139649-21097-1-git-send-email-avarab@gmail.com>
Ævar Arnfjörð Bjarmason wrote:
Show 34 quoted lines
> +++ b/builtin/commit.c
> @@ -565,6 +579,16 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  	if (!no_verify && run_hook(index_file, "pre-commit", NULL))
>  		return 0;
>  
> +	/* Update the index after we run the pre-commit hook, but before
> +	 * we construct the message we're sending to the editor. The
> +	 * pre-commit hook may e.g. create a new file and add it to the
> +	 * index.
> +	 *
> +	 * Having that file show up as modified but not staged is confusing.
> +	 */
> +	if (!update_index(index_file))
> +		return 0;
> +
>  	if (message.len) {
>  		strbuf_addbuf(&sb, &message);
>  		hook_arg1 = "message";
> @@ -728,15 +752,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  	 * and write it out as a tree.  We must do this before we invoke
>  	 * the editor and after we invoke run_status above.
>  	 */
> -	discard_cache();
> -	read_cache_from(index_file);
> -	if (!active_cache_tree)
> -		active_cache_tree = cache_tree();
> -	if (cache_tree_update(active_cache_tree,
> -			      active_cache, active_nr, 0, 0) < 0) {
> -		error("Error building trees");
> +	if (!update_index(index_file))
>  		return 0;
> -	}
>  
>  	if (run_hook(index_file, "prepare-commit-msg",

Before, "commit" updated the index once, and after, twice. How does this affect the running time on, say, the linux-2.6 tree? Could one of the update_index() calls be suppressed when there is no hook to run?

Previous: Junio C Hamano
Message 4 of 4 in “COMMIT_EDITMSG not updated after pre-commit hook”
  1. Hinrik Örn SigurðssonMay 3, 2009
  2. commit: update the index after running the pre-commit hookÆvar Arnfjörð Bjarmason, Aug 18, 2010
  3. Junio C HamanoAug 18, 2010
  4. Jonathan NiederAug 18, 2010

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.