summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-01-06 21:27:42 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-01-06 21:32:08 -0400
commit8e7de0104702d59e327694451303e8fbe53c9ea5 (patch)
treed88304288cf83e39984df73410e1a9836217d888
parent539f8c6f144e7fa9cb76f34c06417e3c13ff3420 (diff)
log --before=date
-rw-r--r--Command/Log.hs38
-rw-r--r--Seek.hs10
-rw-r--r--Usage.hs2
3 files changed, 27 insertions, 23 deletions
diff --git a/Command/Log.hs b/Command/Log.hs
index b28abfc18..3336df873 100644
--- a/Command/Log.hs
+++ b/Command/Log.hs
@@ -24,6 +24,7 @@ import qualified Git
import Git.Command
import qualified Remote
import qualified Option
+import qualified Annex
data RefChange = RefChange
{ changetime :: POSIXTime
@@ -32,29 +33,28 @@ data RefChange = RefChange
}
def :: [Command]
-def = [withOptions [afterOption, maxcountOption] $
+def = [withOptions options $
command "log" paramPaths seek "shows location log"]
-afterOption :: Option
-afterOption = Option.field [] "after" paramDate "show log after date"
-
-maxcountOption :: Option
-maxcountOption = Option.field ['n'] "max-count" paramNumber "limit number of logs displayed"
+options :: [Option]
+options =
+ [ Option.field [] "after" paramDate "show log after date"
+ , Option.field [] "before" paramDate "show log before date"
+ , Option.field ['n'] "max-count" paramNumber "limit number of logs displayed"
+ ]
seek :: [CommandSeek]
-seek = [withField afterOption return $ \afteropt ->
- withField maxcountOption return $ \maxcount ->
- withFilesInGit $ whenAnnexed $ start afteropt maxcount]
+seek = [withValue (concat <$> mapM getoption options) $ \os ->
+ withFilesInGit $ whenAnnexed $ start os]
+ where
+ getoption o = maybe [] (use o) <$>
+ Annex.getField (Option.name o)
+ use o v = [Param ("--" ++ Option.name o), Param v]
-start :: Maybe String -> Maybe String -> FilePath -> (Key, Backend) -> CommandStart
-start afteropt maxcount file (key, _) = do
- showLog file =<< readLog <$> getLog key ps
+start :: [CommandParam] -> FilePath -> (Key, Backend) -> CommandStart
+start os file (key, _) = do
+ showLog file =<< readLog <$> getLog key os
stop
- where
- ps = concatMap (\(o, p) -> maybe [] p o)
- [ (afteropt, \d -> [Param "--after", Param d])
- , (maxcount, \c -> [Param "--max-count", Param c])
- ]
showLog :: FilePath -> [RefChange] -> Annex ()
showLog file ps = do
@@ -87,13 +87,13 @@ showLog file ps = do
[ addel, time, file, "|", r ]
getLog :: Key -> [CommandParam] -> Annex [String]
-getLog key ps = do
+getLog key os = do
top <- fromRepo Git.workTree
p <- liftIO $ relPathCwdToFile top
let logfile = p </> Logs.Location.logFile key
inRepo $ pipeNullSplit $
[ Params "log -z --pretty=format:%ct --raw --abbrev=40"
- ] ++ ps ++
+ ] ++ os ++
[ Param $ show Annex.Branch.fullname
, Param "--"
, Param logfile
diff --git a/Seek.hs b/Seek.hs
index fdb117de0..59a85be88 100644
--- a/Seek.hs
+++ b/Seek.hs
@@ -88,14 +88,18 @@ withKeys a params = return $ map (a . parse) params
where
parse p = fromMaybe (error "bad key") $ readKey p
+withValue :: Annex v -> (v -> CommandSeek) -> CommandSeek
+withValue v a params = do
+ r <- v
+ a r params
+
{- Modifies a seek action using the value of a field option, which is fed into
- a conversion function, and then is passed into the seek action.
- This ensures that the conversion function only runs once.
-}
withField :: Option -> (Maybe String -> Annex a) -> (a -> CommandSeek) -> CommandSeek
-withField option converter a ps = do
- f <- converter =<< Annex.getField (Option.name option)
- a f ps
+withField option converter = withValue $
+ converter =<< Annex.getField (Option.name option)
withNothing :: CommandStart -> CommandSeek
withNothing a [] = return [a]
diff --git a/Usage.hs b/Usage.hs
index 36944053f..34c344b18 100644
--- a/Usage.hs
+++ b/Usage.hs
@@ -73,7 +73,7 @@ paramUUID = "UUID"
paramType :: String
paramType = "TYPE"
paramDate :: String
-paramDate = "Date"
+paramDate = "DATE"
paramFormat :: String
paramFormat = "FORMAT"
paramKeyValue :: String