git-annex/Annex/Debug/Utility.hs
Joey Hess d16d739ce2
implement fastDebug
Most of the changes here involve global option parsing: GlobalSetter
changed so it can both run an Annex action to set state, but can also
change the AnnexRead value, which is immutable once the Annex monad is
running.

That allowed a debugselector value to be added to AnnexRead, seeded
from the git config. The --debugfilter option's GlobalSetter then updates
the AnnexRead.

This improved GlobalSetter can later be used to move more stuff to
AnnexRead. Things that don't involve a git config will be easier to
move, and probably a *lot* of things can be moved eventually.

fastDebug, while implemented, is not used anywhere yet. But it should be
fast..
2021-04-06 15:24:28 -04:00

32 lines
885 B
Haskell

{- git-annex debugging, utility functions
-
- Copyright 2021 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module Annex.Debug.Utility (
debugSelectorFromGitConfig,
parseDebugSelector,
DebugSelector,
) where
import Types.GitConfig
import Utility.Debug
import Utility.Split
import Utility.FileSystemEncoding
import qualified Data.ByteString as S
debugSelectorFromGitConfig :: GitConfig -> DebugSelector
debugSelectorFromGitConfig =
maybe NoDebugSelector parseDebugSelector . annexDebugFilter
parseDebugSelector :: String -> DebugSelector
parseDebugSelector = DebugSelector . matchDebugSource . splitSelectorNames
splitSelectorNames :: String -> [S.ByteString]
splitSelectorNames = map encodeBS . splitc ','
matchDebugSource :: [S.ByteString] -> DebugSource -> Bool
matchDebugSource names (DebugSource s) = any (`S.isInfixOf` s) names