[PATCH v2 19/19] reset [--mixed]: use diff-based reset whether or not pathspec was given
- From
Martin von Zweigbergk <martinvonz@gmail.com>
- Date
- Jan 15, 2013, 05:47 UTC
- Message-ID
- <1358228871-7142-20-git-send-email-martinvonz@gmail.com>
- In-Reply-To
- <1358228871-7142-1-git-send-email-martinvonz@gmail.com>
Thanks to b65982b (Optimize "diff-index --cached" using cache-tree, 2009-05-20), resetting with paths is much faster than resetting without paths. Some timings for the linux-2.6 repo to illustrate this (best of five, warm cache):
reset reset . real 0m0.219s 0m0.080s user 0m0.140s 0m0.040s sys 0m0.070s 0m0.030s
These two commands should do the same thing, so instead of having the user type the trailing " ." to get the faster do_diff_cache()-based implementation, always use it when doing a mixed reset, with or without paths (so "git reset $rev" would also be faster).
Timing "git reset" shows that it indeed becomes as fast as "git reset ." after this patch.
Signed-off-by: Martin von Zweigbergk <martinvonz@gmail.com> --- It seems like a better solution would be for unpack_trees() learn the same tricks as do_diff_cache(). I'm leaving that a challange for the reader :-). I did have a look a unpack_trees(), but it looked rather overwhelming.
builtin/reset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/reset.c b/builtin/reset.c index 45b01eb..921afbe 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -322,7 +322,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) if (reset_type != SOFT) { struct lock_file *lock = xcalloc(1, sizeof(struct lock_file)); int newfd = hold_locked_index(lock, 1); - if (pathspec) { + if (reset_type == MIXED) { if (read_from_tree(pathspec, sha1)) return 1; } else {
-- 1.8.1.1.454.gce43f05