status --json --fast for esc

* status: Fix --json mode (only the repository lists are currently
  displayed)
* status: --fast is back
This commit is contained in:
Joey Hess 2011-11-14 19:27:00 -04:00
parent 02f1d5467a
commit bfe38f8ff1
5 changed files with 41 additions and 10 deletions

View file

@ -18,6 +18,7 @@ import qualified Types.Remote as R
import qualified Remote import qualified Remote
import qualified Command.Unused import qualified Command.Unused
import qualified Git import qualified Git
import qualified Annex
import Command import Command
import Utility.DataUnits import Utility.DataUnits
import Annex.Content import Annex.Content
@ -49,14 +50,17 @@ seek = [withNothing start]
{- Order is significant. Less expensive operations, and operations {- Order is significant. Less expensive operations, and operations
- that share data go together. - that share data go together.
-} -}
stats :: [Stat] fast_stats :: [Stat]
stats = fast_stats =
[ supported_backends [ supported_backends
, supported_remote_types , supported_remote_types
, remote_list Trusted "trusted" , remote_list Trusted "trusted"
, remote_list SemiTrusted "semitrusted" , remote_list SemiTrusted "semitrusted"
, remote_list UnTrusted "untrusted" , remote_list UnTrusted "untrusted"
, tmp_size ]
slow_stats :: [Stat]
slow_stats =
[ tmp_size
, bad_data_size , bad_data_size
, local_annex_keys , local_annex_keys
, local_annex_size , local_annex_size
@ -67,6 +71,10 @@ stats =
start :: CommandStart start :: CommandStart
start = do start = do
showStart "status" "."
showWith $ liftIO $ putStrLn ""
fast <- Annex.getState Annex.fast
let stats = if fast then fast_stats else fast_stats ++ slow_stats
evalStateT (mapM_ showStat stats) (StatInfo Nothing Nothing) evalStateT (mapM_ showStat stats) (StatInfo Nothing Nothing)
stop stop
@ -80,9 +88,11 @@ showStat :: Stat -> StatState ()
showStat s = calc =<< s showStat s = calc =<< s
where where
calc (Just (desc, a)) = do calc (Just (desc, a)) = do
liftIO $ putStr $ desc ++ ": " r <- a -- run first, it may produce JSON
liftIO $ hFlush stdout lift . showWith $ do
liftIO . putStrLn =<< a liftIO $ putStr $ desc ++ ": "
liftIO $ hFlush stdout
liftIO $ putStrLn r
calc Nothing = return () calc Nothing = return ()
supported_backends :: Stat supported_backends :: Stat

View file

@ -20,6 +20,8 @@ module Messages (
warning, warning,
indent, indent,
maybeShowJSON, maybeShowJSON,
showWith,
setupConsole setupConsole
) where ) where
@ -31,7 +33,7 @@ import qualified Annex
import qualified Messages.JSON as JSON import qualified Messages.JSON as JSON
showStart :: String -> String -> Annex () showStart :: String -> String -> Annex ()
showStart command file = handle (JSON.start command file) $ showStart command file = handle (JSON.start command $ Just file) $
flushed $ putStr $ command ++ " " ++ file ++ " " flushed $ putStr $ command ++ " " ++ file ++ " "
showNote :: String -> Annex () showNote :: String -> Annex ()
@ -111,6 +113,16 @@ handle json normal = do
maybeShowJSON :: JSON a => [(String, a)] -> Annex () maybeShowJSON :: JSON a => [(String, a)] -> Annex ()
maybeShowJSON v = handle (JSON.add v) q maybeShowJSON v = handle (JSON.add v) q
{- Performs an a action (such as displaying something) only when
- not in json mode, and not quiet. -}
showWith :: Annex () -> Annex ()
showWith a = do
output <- Annex.getState Annex.output
case output of
Annex.NormalOutput -> a
Annex.QuietOutput -> q
Annex.JSONOutput -> q
q :: Monad m => m () q :: Monad m => m ()
q = return () q = return ()

View file

@ -16,8 +16,12 @@ import Text.JSON
import qualified Utility.JSONStream as Stream import qualified Utility.JSONStream as Stream
start :: String -> String -> IO () start :: String -> Maybe String -> IO ()
start command file = putStr $ Stream.start [("command", command), ("file", file)] start command file =
putStr $ Stream.start $ ("command", command) : filepart file
where
filepart Nothing = []
filepart (Just f) = [("file", f)]
end :: Bool -> IO () end :: Bool -> IO ()
end b = putStr $ Stream.add [("success", b)] ++ Stream.end end b = putStr $ Stream.add [("success", b)] ++ Stream.end

3
debian/changelog vendored
View file

@ -9,6 +9,9 @@ git-annex (3.20111112) UNRELEASED; urgency=low
* Optimised union merging; now only runs git cat-file once. * Optimised union merging; now only runs git cat-file once.
* status: Now displays trusted, untrusted, and semitrusted repositories * status: Now displays trusted, untrusted, and semitrusted repositories
separately. separately.
* status: Fix --json mode (only the repository lists are currently
displayed)
* status: --fast is back
-- Joey Hess <joeyh@debian.org> Sat, 12 Nov 2011 14:50:21 -0400 -- Joey Hess <joeyh@debian.org> Sat, 12 Nov 2011 14:50:21 -0400

View file

@ -240,7 +240,9 @@ subdirectories).
* status * status
Displays some statistics and other information, including how much data Displays some statistics and other information, including how much data
is in the annex. is in the annex and a list of all known repositories.
To only show the data that can be gathered quickly, use --fast.
* map * map