Speed up creation of temporary index when autofixing staged changes
Instead of using "git read-tree" to create an entirely new index, start by copying the old index file, and then subtracting the changes made since HEAD.
This greatly improves performance on a monorepo of 30k files,
where my .git/index file is around 5MB. A run of git-autofixup with
a single staged line and some 100 commits in the topic branch goes
from 6 seconds to merely 0.5. (I didn't investigate why -
a GIT_INDEX_FILE=$(mktemp) git read-tree HEAD^{tree}
only takes 300ms).
Take care to support the case where a user has set their own GIT_INDEX_FILE. This is a bit awkward because we apply it's default value ($GIT_DIR/index) in the callee but I couldn't make it work in the caller.
In a previous attempt I tried to remove the temporary index, see https://github.com/krobelus/git-autofixup/commit/optimize-staged-changes but that approach made it hard to reliably preserve user data in failure scenarios - a little copying is much safer.
@torbiak we've been happily using this performance fix for around a year, how do you feel about merging it? Also #18 is a nice improvement.
@torbiak @krobelus we are using this patch sind Tue Aug 24 15:09:45 2021. No complains so far.
Sorry about the extreme delay in merging this. @krobelus is much more diligent that I am in terms of maintaining git-autofixup, so I've added him as a collaborator.