reset [--mixed]: only write index file once
commitbc41bf422e15209860bfc6c898dbd3cd89d5da34
authorMartin von Zweigbergk <martinvonz@gmail.com>
Tue, 15 Jan 2013 05:47:46 +0000 (14 21:47 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Jan 2013 17:38:08 +0000 (15 09:38 -0800)
tree2013167f8e30e4000b009f25165d9ab2ec4ec67c
parent01a19dfc1ac53011deef492b21e52bf7840cef49
reset [--mixed]: only write index file once

When doing a mixed reset without paths, the index is locked, read,
reset, and written back as part of the actual reset operation (in
reset_index()). Then, when showing the list of worktree modifications,
we lock the index again, refresh it, and write it.

Change this so we only write the index once, making "git reset" a
little faster. It does mean that the index lock will be held a little
longer, but the difference is small compared to the time spent
refreshing the index.

There is one minor functional difference: We used to say "Could not
write new index file." if the first write failed, and "Could not
refresh index" if the second write failed. Now, we will only use the
first message.

This speeds up "git reset" a little on the linux-2.6 repo (best of
five, warm cache):

        Before      After
real    0m0.239s    0m0.214s
user    0m0.160s    0m0.130s
sys     0m0.070s    0m0.080s

Signed-off-by: Martin von Zweigbergk <martinvonz@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/reset.c