, sentinalstatus :: Maybe SentinalStatus
, useragent :: Maybe String
, errcounter :: Integer
+ , skippedfiles :: Bool
, adjustedbranchrefreshcounter :: Integer
, unusedkeys :: Maybe (S.Set Key)
, tempurls :: M.Map Key URLString
, sentinalstatus = Nothing
, useragent = Nothing
, errcounter = 0
+ , skippedfiles = False
, adjustedbranchrefreshcounter = 0
, unusedkeys = Nothing
, tempurls = M.empty
forM_ l $ \(cmd, seek, st) ->
-- The cmd is run for benchmarking without startup or
-- shutdown actions.
- Annex.eval st $ performCommandAction cmd seek noop
+ Annex.eval st $ performCommandAction False cmd seek noop
where
- -- Simplified versio of CmdLine.dispatch, without support for fuzzy
+ -- Simplified version of CmdLine.dispatch, without support for fuzzy
-- matching or out-of-repo commands.
parsesubcommand ps = do
(cmd, seek, globalconfig) <- liftIO $ O.handleParseResult $
forM_ fields $ uncurry Annex.setField
prepRunCommand cmd globalsetter
startup
- performCommandAction cmd seek $
+ performCommandAction True cmd seek $
shutdown $ cmdnocommit cmd
go (Left norepo) = do
let ingitrepo = \a -> a =<< Git.Config.global
import qualified System.Console.Regions as Regions
{- Runs a command, starting with the check stage, and then
- - the seek stage. Finishes by running the continutation, and
- - then showing a count of any failures. -}
-performCommandAction :: Command -> CommandSeek -> Annex () -> Annex ()
-performCommandAction Command { cmdcheck = c, cmdname = name } seek cont = do
+ - the seek stage. Finishes by running the continuation.
+ -
+ - Can exit when there was a problem or when files were skipped.
+ - Also shows a count of any failures when that is enabled.
+ -}
+performCommandAction :: Bool -> Command -> CommandSeek -> Annex () -> Annex ()
+performCommandAction canexit (Command { cmdcheck = c, cmdname = name }) seek cont = do
mapM_ runCheck c
Annex.changeState $ \s -> s { Annex.errcounter = 0 }
seek
finishCommandActions
cont
- showerrcount =<< Annex.getState Annex.errcounter
+ st <- Annex.getState id
+ when canexit $ liftIO $ case (Annex.errcounter st, Annex.skippedfiles st) of
+ (0, False) -> noop
+ (errcnt, False) -> do
+ showerrcount errcnt
+ exitWith $ ExitFailure 1
+ (0, True) -> exitskipped
+ (errcnt, True) -> do
+ showerrcount errcnt
+ exitskipped
where
- showerrcount 0 = noop
- showerrcount cnt = giveup $ name ++ ": " ++ show cnt ++ " failed"
+ showerrcount cnt = hPutStrLn stderr $
+ name ++ ": " ++ show cnt ++ " failed"
+ exitskipped = exitWith $ ExitFailure 101
commandActions :: [CommandStart] -> Annex ()
commandActions = mapM_ commandAction
Nothing -> do
fsz <- catchMaybeIO $ withObjectLoc k $
liftIO . getFileSize
- maybe noop go fsz
+ maybe skipped go fsz
Nothing -> a
where
go sz = do
writeTVar sizelimitvar n'
return True
else return False
- when fits a
+ if fits
+ then a
+ else skipped
+
+ skipped = Annex.changeState $ \s -> s { Annex.skippedfiles = True }
In some cases, an annexed file's size is not known. This option will
prevent git-annex from processing such files.
+ When the size limit prevents git-annex from acting on any files,
+ it will exit with a special code, 101.
+
* `--semitrust=repository`
* `--untrust=repository`
Another issue this could be used to mitigates is that, for some reason, git-annex doesn't auto-stop the transfer when the repos on my external drives are full properly.
I imagine there are many more use-cases where quickly being able to set a limit for the amount of data a command should act on could come in handy.
+
+> [[done]] --[[Joey]]
--- /dev/null
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 2"""
+ date="2021-06-04T20:35:26Z"
+ content="""
+--size-limit is implemented, for most git-annex commands.
+
+Ones like `git-annex add` that don't operate on annexed files don't support
+it, at least yet.
+
+Ones like git-annex export/import/sync I'm not sure it makes sense to
+support it, since they kind of operate at a higher level than individual
+files.
+"""]]