diff options
-rw-r--r-- | GitAnnex.hs | 4 | ||||
-rw-r--r-- | Limit.hs | 16 | ||||
-rw-r--r-- | Usage.hs | 2 | ||||
-rw-r--r-- | Utility/HumanTime.hs | 26 | ||||
-rw-r--r-- | debian/changelog | 2 | ||||
-rw-r--r-- | doc/git-annex.mdwn | 17 |
6 files changed, 63 insertions, 4 deletions
diff --git a/GitAnnex.hs b/GitAnnex.hs index 67aead173..c6fc5210f 100644 --- a/GitAnnex.hs +++ b/GitAnnex.hs @@ -141,9 +141,11 @@ options = Option.common ++ "skip files with fewer copies" , Option ['B'] ["inbackend"] (ReqArg Limit.addInBackend paramName) "skip files not using a key-value backend" + , Option ['T'] ["time-limit"] (ReqArg Limit.addTimeLimit paramTime) + "stop after the specified amount of time" ] ++ Option.matcher where - setnumcopies v = Annex.changeState $ \s -> s {Annex.forcenumcopies = readish v } + setnumcopies v = Annex.changeState $ \s -> s { Annex.forcenumcopies = readish v } setgitconfig :: String -> Annex () setgitconfig v = do newg <- inRepo $ Git.Config.store v @@ -9,6 +9,7 @@ module Limit where import Text.Regex.PCRE.Light.Char8 import System.Path.WildMatch +import Data.Time.Clock.POSIX import Common.Annex import qualified Annex @@ -17,6 +18,7 @@ import qualified Remote import qualified Backend import Annex.Content import Logs.Trust +import Utility.HumanTime type Limit = Utility.Matcher.Token (FilePath -> Annex Bool) @@ -106,3 +108,17 @@ addInBackend name = addLimit $ Backend.lookupFile >=> check where wanted = Backend.lookupBackendName name check = return . maybe False ((==) wanted . snd) + +addTimeLimit :: String -> Annex () +addTimeLimit s = do + let seconds = fromMaybe (error "bad time-limit") $ parseDuration s + start <- liftIO getPOSIXTime + let cutoff = start + seconds + addLimit $ const $ do + now <- liftIO getPOSIXTime + if now > cutoff + then do + warning $ "Time limit (" ++ s ++ ") reached!" + liftIO $ exitWith $ ExitFailure 101 + else return True + @@ -77,6 +77,8 @@ paramType :: String paramType = "TYPE" paramDate :: String paramDate = "DATE" +paramTime :: String +paramTime = "TIME" paramFormat :: String paramFormat = "FORMAT" paramFile :: String diff --git a/Utility/HumanTime.hs b/Utility/HumanTime.hs new file mode 100644 index 000000000..ca631dbb1 --- /dev/null +++ b/Utility/HumanTime.hs @@ -0,0 +1,26 @@ +{- Time for humans. + - + - Copyright 2012 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Utility.HumanTime where + +import Utility.PartialPrelude + +import Data.Time.Clock.POSIX (POSIXTime) + +{- Parses a human-input time duration, of the form "5h" or "1m". -} +parseDuration :: String -> Maybe POSIXTime +parseDuration s = do + num <- readish s :: Maybe Integer + units <- findUnits =<< lastMaybe s + return $ fromIntegral num * units + where + findUnits 's' = Just 1 + findUnits 'm' = Just 60 + findUnits 'h' = Just $ 60 * 60 + findUnits 'd' = Just $ 60 * 60 * 24 + findUnits 'y' = Just $ 60 * 60 * 24 * 365 + findUnits _ = Nothing diff --git a/debian/changelog b/debian/changelog index e8077d296..acdbe24cc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,8 @@ git-annex (3.20120925) UNRELEASED; urgency=low with git annex fsck --incremental. Now the fsck can be interrupted as desired, and resumed with git annex fsck --more. Thanks, Justin Azoff + * New --time-limit option, makes long git-annex commands stop after + a specified amount of time. -- Joey Hess <joeyh@debian.org> Mon, 24 Sep 2012 19:58:07 -0400 diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index cf6a0c6bd..ffcfa1f3b 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -259,13 +259,13 @@ subdirectories). To check a remote to fsck, specify --from. + To avoid expensive checksum calculations (and expensive transfers when + fscking a remote), specify --fast. + To start a new incremental fsck, specify --incremental. Then the next time you fsck, you can specify --more to skip over files that have already been checked, and continue where it left off. - To avoid expensive checksum calculations (and expensive transfers when - fscking a remote), specify --fast. - * unused Checks the annex for data that does not correspond to any files present @@ -514,6 +514,17 @@ subdirectories). Overrides the `annex.numcopies` setting, forcing git-annex to ensure the specified number of copies exist. +* --time-limit=time + + Limits how long a git-annex command runs. The time can be something + like "5h", or "30m" or even "45s" or "10d". + + Note that git-annex may continue running a little past the specified + time limit, in order to finish processing a file. + + Also, note that if the time limit prevents git-annex from doing all it + was asked to, it will exit with a special code, 101. + * --trust=repository * --semitrust=repository * --untrust=repository |