Speed up implementation of checking out a commit 

See commit message for detailed explanation.