summaryrefslogtreecommitdiff
path: root/Command/Log.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-01-07 00:11:15 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-01-07 00:11:15 -0400
commit945f56f348c9c4963dbd6b6c969498a28da068bc (patch)
tree4f7526a02c9c2ec39e8097cc5d30dac1654a4c0e /Command/Log.hs
parent24b35113cf67cf8effd1f70f81fc4ae43987e6a0 (diff)
cleanup
Broke out pure general functions etc.
Diffstat (limited to 'Command/Log.hs')
-rw-r--r--Command/Log.hs25
1 files changed, 16 insertions, 9 deletions
diff --git a/Command/Log.hs b/Command/Log.hs
index 0e0c8d3a0..eba9226e5 100644
--- a/Command/Log.hs
+++ b/Command/Log.hs
@@ -63,7 +63,7 @@ showLog file ps = do
zone <- liftIO getCurrentTimeZone
sets <- mapM (getset newref) ps
previous <- maybe (return genesis) (getset oldref) (lastMaybe ps)
- mapM_ (diff file zone) $ zip sets (drop 1 sets ++ [previous])
+ sequence_ $ compareChanges (output zone) $ sets ++ [previous]
where
genesis = (0, S.empty)
getset select change = do
@@ -71,22 +71,29 @@ showLog file ps = do
return (changetime change, s)
get ref = map toUUID . Logs.Presence.getLog . L.unpack <$>
catObject ref
-
-diff :: FilePath -> TimeZone -> ((POSIXTime, S.Set UUID), (POSIXTime, S.Set UUID)) -> Annex ()
-diff file zone ((ts, new), (_, old)) = output True added >> output False removed
- where
- added = S.difference new old
- removed = S.difference old new
- time = showTimeStamp zone ts
- output present s = do
+ output zone present ts s = do
rs <- map (dropWhile isSpace) . lines <$>
Remote.prettyPrintUUIDs "log" (S.toList s)
liftIO $ mapM_ (putStrLn . format) rs
where
+ time = showTimeStamp zone ts
addel = if present then "+" else "-"
format r = unwords
[ addel, time, file, "|", r ]
+{- Generates a display of the changes (which are ordered with newest first),
+ - by comparing each change with the previous change.
+ - Uses a formater to generate a display of items that are added and
+ - removed. -}
+compareChanges :: Ord a => (Bool -> POSIXTime -> S.Set a -> b) -> [(POSIXTime, S.Set a)] -> [b]
+compareChanges format changes = concatMap diff $ zip changes (drop 1 changes)
+ where
+ diff ((ts, new), (_, old)) =
+ [format True ts added, format False ts removed]
+ where
+ added = S.difference new old
+ removed = S.difference old new
+
getLog :: Key -> [CommandParam] -> Annex [String]
getLog key os = do
top <- fromRepo Git.workTree