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?