checkout: optimize "git checkout -b <new_branch>"
commitfa655d8411cc2d7ffcf898e53a1493c737d7de68
authorBen Peart <Ben.Peart@microsoft.com>
Thu, 16 Aug 2018 18:27:11 +0000 (16 18:27 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Aug 2018 18:54:57 +0000 (16 11:54 -0700)
tree80a88418d738aa4701155f7c3cf3cc38b6836052
parentffc6fa0e396238de3a30623912980263b4f283ab
checkout: optimize "git checkout -b <new_branch>"

Skip merging the commit, updating the index and working directory if and
only if we are creating a new branch via "git checkout -b <new_branch>."
Any other checkout options will still go through the former code path.

If sparse_checkout is on, require the user to manually opt in to this
optimzed behavior by setting the config setting checkout.optimizeNewBranch
to true as we will no longer update the skip-worktree bit in the index, nor
add/remove files in the working directory to reflect the current sparse
checkout settings.

For comparison, running "git checkout -b <new_branch>" on a large repo takes:

14.6 seconds - without this patch
0.3 seconds - with this patch

Signed-off-by: Ben Peart <Ben.Peart@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt
builtin/checkout.c
t/t1090-sparse-checkout-scope.sh