Re: [PATCH 3/3] cache-tree: Write index with updated cache-tree after commit
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 30, 2014, 18:10 UTC
- Message-ID
- <xmqqegy6z2t0.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <1403914856-3546-3-git-send-email-dturner@twitter.com>
David Turner <dturner@twopensource.com> writes:
Show 33 quoted lines
> During the commit process, the cache-tree is updated. We need to write
> this updated cache-tree so that it's ready for subsequent commands.
>
> Add test code which demonstrates that git commit now writes the cache
> tree. Also demonstrate that cache-tree invalidation is correct.
>
> Signed-off-by: David Turner <dturner@twitter.com>
> ---
> builtin/commit.c | 6 ++++++
> t/t0090-cache-tree.sh | 50 +++++++++++++++++++++++++++++++++++++++++++++++---
> 2 files changed, 53 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 9cfef6c..6814e87 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -607,6 +607,8 @@ 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;
> + static struct lock_file index_lock;
> + int index_fd;
>
> /* This checks and barfs if author is badly specified */
> determine_author_info(author_ident);
> @@ -872,6 +874,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
> error(_("Error building trees"));
> return 0;
> }
> + /* After updating the cache-tree, rewrite the index */
> + index_fd = hold_locked_index(&index_lock, 0);
> + if (index_fd >= 0 && write_index(&the_index, index_fd) >= 0)
> + commit_locked_index(&index_lock);Is this run unconditionally even when we are making a partial commit out of a temporary index file (which will be discarded after we create this commit)?
I have a feeling that a better place to populate the cache-tree may be prepare-index which knows the distinction between various modes of commit, but I haven't looked at the code path for a while...