log --before=date
This commit is contained in:
parent
539f8c6f14
commit
8e7de01047
3 changed files with 28 additions and 24 deletions
|
@ -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]
|
||||
|
||||
start :: Maybe String -> Maybe String -> FilePath -> (Key, Backend) -> CommandStart
|
||||
start afteropt maxcount file (key, _) = do
|
||||
showLog file =<< readLog <$> getLog key ps
|
||||
stop
|
||||
seek = [withValue (concat <$> mapM getoption options) $ \os ->
|
||||
withFilesInGit $ whenAnnexed $ start os]
|
||||
where
|
||||
ps = concatMap (\(o, p) -> maybe [] p o)
|
||||
[ (afteropt, \d -> [Param "--after", Param d])
|
||||
, (maxcount, \c -> [Param "--max-count", Param c])
|
||||
]
|
||||
getoption o = maybe [] (use o) <$>
|
||||
Annex.getField (Option.name o)
|
||||
use o v = [Param ("--" ++ Option.name o), Param v]
|
||||
|
||||
start :: [CommandParam] -> FilePath -> (Key, Backend) -> CommandStart
|
||||
start os file (key, _) = do
|
||||
showLog file =<< readLog <$> getLog key os
|
||||
stop
|
||||
|
||||
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
|
||||
|
|
10
Seek.hs
10
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]
|
||||
|
|
2
Usage.hs
2
Usage.hs
|
@ -73,7 +73,7 @@ paramUUID = "UUID"
|
|||
paramType :: String
|
||||
paramType = "TYPE"
|
||||
paramDate :: String
|
||||
paramDate = "Date"
|
||||
paramDate = "DATE"
|
||||
paramFormat :: String
|
||||
paramFormat = "FORMAT"
|
||||
paramKeyValue :: String
|
||||
|
|
Loading…
Add table
Reference in a new issue