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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 10, 2017, 22:22 UTC
Message-ID
<xmqqo9rn12rl.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170810185416.8224-1-kewillf@microsoft.com>
Kevin Willford <kcwillford@gmail.com> writes:
Show 8 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>
> ---

Peff already has done a good job reviewing the patch text, and I agree that this is a worthwhile optimization.

Could Microsoft folks all make sure that their signed-off-by lines match their From: address (or leave an in-body From: to override the From: address your MUA places in your messages)?

Thanks.
Show 54 quoted lines
>  builtin/commit.c | 29 +++++++++++++++++++++--------
>  1 file changed, 21 insertions(+), 8 deletions(-)
>
> diff --git a/builtin/commit.c b/builtin/commit.c
> index e7a2cb6285..443949d87b 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -671,12 +671,22 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  	const char *hook_arg2 = NULL;
>  	int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
>  	int old_display_comment_prefix;
> +	const char *precommit_hook = NULL;
>  
>  	/* This checks and barfs if author is badly specified */
>  	determine_author_info(author_ident);
>  
> -	if (!no_verify && run_commit_hook(use_editor, index_file, "pre-commit", NULL))
> -		return 0;
> +
> +	if (!no_verify) {
> +		/*
> +		 * Check to see if there is a pre-commit hook
> +		 * If there not one we can skip discarding the index later on
> +		 */
> +		precommit_hook = find_hook("pre-commit");
> +		if (precommit_hook &&
> +		    run_commit_hook(use_editor, index_file, "pre-commit", NULL))
> +			return 0;
> +	}
>  
>  	if (squash_message) {
>  		/*
> @@ -940,12 +950,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 && precommit_hook) {
> +		/*
> +		 * 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);
>  	if (update_main_cache_tree(0)) {
>  		error(_("Error building trees"));
Previous: Jeff KingNext: Kevin Willford
Message 3 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.