sped up the --all option by 2x to 16x by using git cat-file --buffer

This assumes that no location log files will have a newline or carriage
return in their name. catObjectStream skips any such files due to
cat-file not supporting them.

Keys have been prevented from containing newlines since 2011,
commit 480495beb4. If some old repo
had a key with a newline in it, --all will just skip processing that key.
Other things, like .git/annex/unused files certianly assume no newlines in
keys too, and AFAICR, such keys never actually worked.

Carriage return is escaped by preSanitizeKeyName since 2013. WORM keys
generated before that point could perhaps contain a CR. (URL probably not,
http probably doesn't support an URL with a raw CR in it.) So, added
a warning in fsck about such keys. Although, fsck --all will naturally
skip them, so won't be able to warn about them. Not entirely
satisfactory, but I'll bet there are not really any such keys in
existence.

Thanks to Lukey for finding this optimisation.
This commit is contained in:
Joey Hess 2020-07-07 13:46:45 -04:00
parent 98e2e3cb9c
commit d010ab04be
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 162 additions and 24 deletions

View file

@ -22,16 +22,19 @@ import qualified Git.LsTree as LsTree
import Git.FilePath
import qualified Limit
import CmdLine.GitAnnex.Options
import Logs.Location
import Logs
import Logs.Unused
import Types.Transfer
import Logs.Transfer
import Remote.List
import qualified Remote
import Annex.CatFile
import Git.CatFile (catObjectStream)
import Annex.CurrentBranch
import Annex.Content
import Annex.InodeSentinal
import qualified Annex.Branch
import qualified Annex.BranchState
import qualified Database.Keys
import qualified Utility.RawFilePath as R
@ -180,26 +183,55 @@ withKeyOptions' ko auto mkkeyaction fallbackaction params = do
giveup "Cannot use --auto in a bare repository"
case (null params, ko) of
(True, Nothing)
| bare -> noauto $ runkeyaction finishCheck loggedKeys
| bare -> noauto runallkeys
| otherwise -> fallbackaction params
(False, Nothing) -> fallbackaction params
(True, Just WantAllKeys) -> noauto $ runkeyaction finishCheck loggedKeys
(True, Just WantUnusedKeys) -> noauto $ runkeyaction (pure . Just) unusedKeys'
(True, Just WantAllKeys) -> noauto runallkeys
(True, Just WantUnusedKeys) -> noauto $ runkeyaction unusedKeys'
(True, Just WantFailedTransfers) -> noauto runfailedtransfers
(True, Just (WantSpecificKey k)) -> noauto $ runkeyaction (pure . Just) (return [k])
(True, Just WantIncompleteKeys) -> noauto $ runkeyaction (pure . Just) incompletekeys
(True, Just (WantSpecificKey k)) -> noauto $ runkeyaction (return [k])
(True, Just WantIncompleteKeys) -> noauto $ runkeyaction incompletekeys
(True, Just (WantBranchKeys bs)) -> noauto $ runbranchkeys bs
(False, Just _) -> giveup "Can only specify one of file names, --all, --branch, --unused, --failed, --key, or --incomplete"
where
noauto a
| auto = giveup "Cannot use --auto with --all or --branch or --unused or --key or --incomplete"
| otherwise = a
incompletekeys = staleKeysPrune gitAnnexTmpObjectDir True
runkeyaction checker getks = do
-- List all location log files on the git-annex branch,
-- and use those to get keys. Pass through cat-file
-- to get the contents of the location logs, and pre-cache
-- those. This significantly speeds up typical operations
-- that need to look at the location log for each key.
runallkeys = do
keyaction <- mkkeyaction
config <- Annex.getGitConfig
g <- Annex.gitRepo
void Annex.Branch.update
(l, cleanup) <- inRepo $ LsTree.lsTree
LsTree.LsTreeRecursive
Annex.Branch.fullname
let getk = locationLogFileKey config . getTopFilePath
let go reader = liftIO reader >>= \case
Nothing -> return ()
Just (f, content) -> do
case getk f of
Just k -> do
Annex.BranchState.setCache (getTopFilePath f) content
keyaction (k, mkActionItem k)
Nothing -> return ()
go reader
catObjectStream l (isJust . getk . LsTree.file) g go
liftIO $ void cleanup
runkeyaction getks = do
keyaction <- mkkeyaction
ks <- getks
forM_ ks $ checker >=> maybe noop
(\k -> keyaction (k, mkActionItem k))
forM_ ks $ \k -> keyaction (k, mkActionItem k)
runbranchkeys bs = do
keyaction <- mkkeyaction
forM_ bs $ \b -> do
@ -211,6 +243,7 @@ withKeyOptions' ko auto mkkeyaction fallbackaction params = do
in keyaction (k, bfp)
unlessM (liftIO cleanup) $
error ("git ls-tree " ++ Git.fromRef b ++ " failed")
runfailedtransfers = do
keyaction <- mkkeyaction
rs <- remoteList