avoid git check-ignore overhead on importing known files
authorJoey Hess <joeyh@joeyh.name>
Wed, 30 Sep 2020 15:09:09 +0000 (11:09 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 30 Sep 2020 15:20:44 +0000 (11:20 -0400)
commit41271e4eb4b3843b3e413d9fd96781103a3974c5
tree9d0377a1235d0ab603ca55dcd18f1d601313f724
parentc56efbbdb682482e4c773aabe5ed6e69acd9c945
avoid git check-ignore overhead on importing known files

isKnownImportLocation does a database lookup and there's an index
to make that lookup fast, so it's probably faster than talking to git
check-ignore. Checking the matcher is faster still.

While before the gitignore check was added it did not need to always
check isknown, now it does, because it's that or the more expensive
notignored. But at least we can skip notignored when a file is known,
which will often be the common case: Importing from a remote that's been
exported to, and/or imported from before, only new files will not be
known, so only those will need to check notignored.

At first, I had this:
(matches <&&> (isknown <||> notignored)) <||> isknown
Notice that checks isknown every time, whether it matches or not.

So, it's no slower to instead do this:
isknown <||> (matches <&&> notignored)
That has the benefit that, when it's known, it doesn't need to run
matches, which while faster than isknown, is still going to use some CPU.

And it perhaps more clearly expresses the condition: Any known file is
wanted, otherwise it's down to what matches and is not ignored.

This commit was sponsored by Jack Hill on Patren.
Annex/Import.hs