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

Re: [PATCH v2] commit: skip discarding the index if there is no pre-commit hook

From
Jeff King <peff@peff.net>
Date
Aug 14, 2017, 22:13 UTC
Message-ID
<20170814221309.tg7wizmvx3gtzfc7@sigill.intra.peff.net>
In-Reply-To
<20170814215425.23784-1-kewillf@microsoft.com>
On Mon, Aug 14, 2017 at 03:54:25PM -0600, Kevin Willford wrote:
Show 10 quoted lines
> If there is not a pre-commit hook, there is no reason to discard
> the index and reread it.
> 
> This change checks to presence of a pre-commit hook and then only
> discards the index if there was one.
> 
> Signed-off-by: Kevin Willford <kewillf@microsoft.com>
> ---
>  builtin/commit.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
Thanks, this looks nice and simple.
Show 24 quoted lines
> diff --git a/builtin/commit.c b/builtin/commit.c
> index e7a2cb6285..ab71b93518 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -940,12 +940,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  		return 0;
>  	}
>  
> -	/*
> -	 * Re-read the index as pre-commit hook could have updated it,
> -	 * 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();
> +	if (!no_verify && find_hook("pre-commit")) {
> +		/*
> +		 * Re-read the index as pre-commit hook could have updated it,
> +		 * 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);

This read_cache_from() should be a noop, right, because it immediately sees istate->initialized is set? So it shouldn't matter that it is not in the conditional with discard_cache(). Though if its only purpose is to re-read the just-discarded contents, perhaps it makes sense to put it there for readability.

-Peff
Previous: Kevin WillfordNext: Kevin Willford
Message 5 of 8 in “commit: skip discarding the index if there is no pre-commit hook”
  1. commit: skip discarding the index if there is no pre-commit hookKevin Willford, Aug 10, 2017
  2. Jeff KingAug 10, 2017
  3. Junio C HamanoAug 10, 2017
  4. commit: skip discarding the index if there is no pre-commit hookKevin Willford, Aug 14, 2017
  5. Jeff KingAug 14, 2017
  6. Kevin WillfordAug 15, 2017
  7. Jeff KingAug 15, 2017
  8. Junio C HamanoAug 15, 2017

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.