unify batch mode with non-batch by using AnnexedFileSeeker

This commit is contained in:
Joey Hess 2020-07-22 14:23:28 -04:00
parent d9ae6ab0b4
commit 1be92381ec
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
23 changed files with 70 additions and 74 deletions

View file

@ -43,9 +43,6 @@ performCommandAction Command { cmdcheck = c, cmdname = name } seek cont = do
commandActions :: [CommandStart] -> Annex ()
commandActions = mapM_ commandAction
commandAction' :: (a -> b -> CommandStart) -> a -> b -> Annex ()
commandAction' start a b = commandAction $ start a b
{- Runs one of the actions needed to perform a command.
- Individual actions can fail without stopping the whole command,
- including by throwing non-async exceptions.

View file

@ -1,6 +1,6 @@
{- git-annex batch commands
-
- Copyright 2015 Joey Hess <id@joeyh.name>
- Copyright 2015-2020 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
@ -11,10 +11,13 @@ import Annex.Common
import Types.Command
import CmdLine.Action
import CmdLine.GitAnnex.Options
import CmdLine.Seek
import Options.Applicative
import Limit
import Types.FileMatcher
import Annex.BranchState
import Annex.WorkTree
import Annex.Content
data BatchMode = Batch BatchFormat | NoBatch
@ -110,12 +113,22 @@ batchStart fmt a = batchInput fmt (Right <$$> liftIO . relPathCwdToFile) $
-- Like batchStart, but checks the file matching options
-- and skips non-matching files.
batchFilesMatching :: BatchFormat -> (FilePath -> CommandStart) -> Annex ()
batchFilesMatching :: BatchFormat -> (RawFilePath -> CommandStart) -> Annex ()
batchFilesMatching fmt a = do
matcher <- getMatcher
batchStart fmt $ \f ->
let f' = toRawFilePath f
in ifM (matcher $ MatchingFile $ FileInfo f' f')
( a f
( a f'
, return Nothing
)
batchAnnexedFilesMatching :: BatchFormat -> AnnexedFileSeeker -> Annex ()
batchAnnexedFilesMatching fmt seeker = batchFilesMatching fmt $
whenAnnexed $ \f k -> case checkContentPresent seeker of
Just v -> do
present <- inAnnex k
if (present == v)
then startAction seeker f k
else return Nothing
Nothing -> startAction seeker f k

View file

@ -44,12 +44,13 @@ import qualified Annex.BranchState
import qualified Database.Keys
import qualified Utility.RawFilePath as R
import Utility.Tuple
import CmdLine.Action
import Control.Concurrent.Async
import System.Posix.Types
data AnnexedFileSeeker = AnnexedFileSeeker
{ seekAction :: RawFilePath -> Key -> CommandSeek
{ startAction :: RawFilePath -> Key -> CommandStart
, checkContentPresent :: Maybe Bool
, usesLocationLog :: Bool
}
@ -305,7 +306,8 @@ seekFilteredKeys seeker listfs = do
Just (f, content) -> do
case parseLinkTargetOrPointerLazy =<< content of
Just k -> checkpresence k $
seekAction seeker f k
commandAction $
startAction seeker f k
Nothing -> noop
finisher oreader
Nothing -> return ()
@ -313,7 +315,7 @@ seekFilteredKeys seeker listfs = do
precachefinisher lreader = liftIO lreader >>= \case
Just ((logf, f, k), logcontent) -> do
maybe noop (Annex.BranchState.setCache logf) logcontent
seekAction seeker f k
commandAction $ startAction seeker f k
precachefinisher lreader
Nothing -> return ()