From: Junio C Hamano Date: Wed, 09 Jan 2013 19:55:25 GMT Subject: Re: [PATCH 10/19] reset --keep: only write index file once Message-ID: <7vd2xe5dxu.fsf@alter.siamese.dyndns.org> In-Reply-To: <1357719376-16406-11-git-send-email-martinvonz@gmail.com> Martin von Zweigbergk writes: > "git reset --keep" calls reset_index_file() twice, first doing a > two-way merge to the target revision, updating the index and worktree, > and then resetting the index. After each call, we write the index > file. > > In the unlikely event that the second call to reset_index_file() > fails, the index will have been merged to the target revision, but > HEAD will not be updated, leaving the user with a dirty index. > > By moving the locking, writing and committing out of > reset_index_file() and into the caller, we can avoid writing the index > twice, thereby making the sure we don't end up in the half-way reset > state. Nice.