--size-limit exit 101
Sponsored-by: Mark Reidenbach on Patreon
This commit is contained in:
parent
771a122c9e
commit
8a13bbedd6
7 changed files with 50 additions and 12 deletions
2
Annex.hs
2
Annex.hs
|
@ -189,6 +189,7 @@ data AnnexState = AnnexState
|
||||||
, sentinalstatus :: Maybe SentinalStatus
|
, sentinalstatus :: Maybe SentinalStatus
|
||||||
, useragent :: Maybe String
|
, useragent :: Maybe String
|
||||||
, errcounter :: Integer
|
, errcounter :: Integer
|
||||||
|
, skippedfiles :: Bool
|
||||||
, adjustedbranchrefreshcounter :: Integer
|
, adjustedbranchrefreshcounter :: Integer
|
||||||
, unusedkeys :: Maybe (S.Set Key)
|
, unusedkeys :: Maybe (S.Set Key)
|
||||||
, tempurls :: M.Map Key URLString
|
, tempurls :: M.Map Key URLString
|
||||||
|
@ -248,6 +249,7 @@ newAnnexState c r = do
|
||||||
, sentinalstatus = Nothing
|
, sentinalstatus = Nothing
|
||||||
, useragent = Nothing
|
, useragent = Nothing
|
||||||
, errcounter = 0
|
, errcounter = 0
|
||||||
|
, skippedfiles = False
|
||||||
, adjustedbranchrefreshcounter = 0
|
, adjustedbranchrefreshcounter = 0
|
||||||
, unusedkeys = Nothing
|
, unusedkeys = Nothing
|
||||||
, tempurls = M.empty
|
, tempurls = M.empty
|
||||||
|
|
|
@ -32,9 +32,9 @@ mkGenerator cmds userinput = do
|
||||||
forM_ l $ \(cmd, seek, st) ->
|
forM_ l $ \(cmd, seek, st) ->
|
||||||
-- The cmd is run for benchmarking without startup or
|
-- The cmd is run for benchmarking without startup or
|
||||||
-- shutdown actions.
|
-- shutdown actions.
|
||||||
Annex.eval st $ performCommandAction cmd seek noop
|
Annex.eval st $ performCommandAction False cmd seek noop
|
||||||
where
|
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.
|
-- matching or out-of-repo commands.
|
||||||
parsesubcommand ps = do
|
parsesubcommand ps = do
|
||||||
(cmd, seek, globalconfig) <- liftIO $ O.handleParseResult $
|
(cmd, seek, globalconfig) <- liftIO $ O.handleParseResult $
|
||||||
|
|
|
@ -62,7 +62,7 @@ dispatch' subcommandname args fuzzy cmds allargs allcmds fields getgitrepo progn
|
||||||
forM_ fields $ uncurry Annex.setField
|
forM_ fields $ uncurry Annex.setField
|
||||||
prepRunCommand cmd globalsetter
|
prepRunCommand cmd globalsetter
|
||||||
startup
|
startup
|
||||||
performCommandAction cmd seek $
|
performCommandAction True cmd seek $
|
||||||
shutdown $ cmdnocommit cmd
|
shutdown $ cmdnocommit cmd
|
||||||
go (Left norepo) = do
|
go (Left norepo) = do
|
||||||
let ingitrepo = \a -> a =<< Git.Config.global
|
let ingitrepo = \a -> a =<< Git.Config.global
|
||||||
|
|
|
@ -30,19 +30,32 @@ import qualified Data.Map.Strict as M
|
||||||
import qualified System.Console.Regions as Regions
|
import qualified System.Console.Regions as Regions
|
||||||
|
|
||||||
{- Runs a command, starting with the check stage, and then
|
{- Runs a command, starting with the check stage, and then
|
||||||
- the seek stage. Finishes by running the continutation, and
|
- the seek stage. Finishes by running the continuation.
|
||||||
- then showing a count of any failures. -}
|
-
|
||||||
performCommandAction :: Command -> CommandSeek -> Annex () -> Annex ()
|
- Can exit when there was a problem or when files were skipped.
|
||||||
performCommandAction Command { cmdcheck = c, cmdname = name } seek cont = do
|
- 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
|
mapM_ runCheck c
|
||||||
Annex.changeState $ \s -> s { Annex.errcounter = 0 }
|
Annex.changeState $ \s -> s { Annex.errcounter = 0 }
|
||||||
seek
|
seek
|
||||||
finishCommandActions
|
finishCommandActions
|
||||||
cont
|
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
|
where
|
||||||
showerrcount 0 = noop
|
showerrcount cnt = hPutStrLn stderr $
|
||||||
showerrcount cnt = giveup $ name ++ ": " ++ show cnt ++ " failed"
|
name ++ ": " ++ show cnt ++ " failed"
|
||||||
|
exitskipped = exitWith $ ExitFailure 101
|
||||||
|
|
||||||
commandActions :: [CommandStart] -> Annex ()
|
commandActions :: [CommandStart] -> Annex ()
|
||||||
commandActions = mapM_ commandAction
|
commandActions = mapM_ commandAction
|
||||||
|
@ -315,7 +328,7 @@ checkSizeLimit (Just sizelimitvar) startmsg a =
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
fsz <- catchMaybeIO $ withObjectLoc k $
|
fsz <- catchMaybeIO $ withObjectLoc k $
|
||||||
liftIO . getFileSize
|
liftIO . getFileSize
|
||||||
maybe noop go fsz
|
maybe skipped go fsz
|
||||||
Nothing -> a
|
Nothing -> a
|
||||||
where
|
where
|
||||||
go sz = do
|
go sz = do
|
||||||
|
@ -327,4 +340,8 @@ checkSizeLimit (Just sizelimitvar) startmsg a =
|
||||||
writeTVar sizelimitvar n'
|
writeTVar sizelimitvar n'
|
||||||
return True
|
return True
|
||||||
else return False
|
else return False
|
||||||
when fits a
|
if fits
|
||||||
|
then a
|
||||||
|
else skipped
|
||||||
|
|
||||||
|
skipped = Annex.changeState $ \s -> s { Annex.skippedfiles = True }
|
||||||
|
|
|
@ -89,6 +89,9 @@ Most of these options are accepted by all git-annex commands.
|
||||||
In some cases, an annexed file's size is not known. This option will
|
In some cases, an annexed file's size is not known. This option will
|
||||||
prevent git-annex from processing such files.
|
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`
|
* `--semitrust=repository`
|
||||||
* `--untrust=repository`
|
* `--untrust=repository`
|
||||||
|
|
||||||
|
|
|
@ -5,3 +5,5 @@ This way you could quickly "garbage collect" a few dozen GiB from your annex rep
|
||||||
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.
|
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.
|
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]]
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
[[!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.
|
||||||
|
"""]]
|
Loading…
Reference in a new issue