diff options
Diffstat (limited to 'Command/Info.hs')
-rw-r--r-- | Command/Info.hs | 141 |
1 files changed, 108 insertions, 33 deletions
diff --git a/Command/Info.hs b/Command/Info.hs index 63bc92bbe..96b7eb6d7 100644 --- a/Command/Info.hs +++ b/Command/Info.hs @@ -1,6 +1,6 @@ {- git-annex command - - - Copyright 2011 Joey Hess <joey@kitenet.net> + - Copyright 2011-2014 Joey Hess <joey@kitenet.net> - - Licensed under the GNU GPL version 3 or higher. -} @@ -16,14 +16,16 @@ import Data.Tuple import Data.Ord import Common.Annex -import qualified Remote import qualified Command.Unused import qualified Git import qualified Annex +import qualified Remote +import qualified Types.Remote as Remote import Command import Utility.DataUnits import Utility.DiskFree import Annex.Content +import Annex.Link import Types.Key import Logs.UUID import Logs.Trust @@ -65,42 +67,67 @@ data StatInfo = StatInfo , referencedData :: Maybe KeyData , numCopiesStats :: Maybe NumCopiesStats } + +emptyStatInfo :: StatInfo +emptyStatInfo = StatInfo Nothing Nothing Nothing -- a state monad for running Stats in type StatState = StateT StatInfo Annex -def :: [Command] -def = [noCommit $ dontCheck repoExists $ withOptions [jsonOption] $ - command "info" paramPaths seek SectionQuery - "shows general information about the annex"] +cmd :: [Command] +cmd = [noCommit $ dontCheck repoExists $ withOptions [jsonOption] $ + command "info" (paramOptional $ paramRepeating paramItem) seek SectionQuery + "shows information about the specified item or the repository as a whole"] seek :: CommandSeek seek = withWords start -start :: [FilePath] -> CommandStart +start :: [String] -> CommandStart start [] = do globalInfo stop start ps = do - mapM_ localInfo =<< filterM isdir ps + mapM_ itemInfo ps stop - where - isdir = liftIO . catchBoolIO . (isDirectory <$$> getFileStatus) globalInfo :: Annex () globalInfo = do stats <- selStats global_fast_stats global_slow_stats showCustom "info" $ do - evalStateT (mapM_ showStat stats) (StatInfo Nothing Nothing Nothing) + evalStateT (mapM_ showStat stats) emptyStatInfo return True -localInfo :: FilePath -> Annex () -localInfo dir = showCustom (unwords ["info", dir]) $ do - stats <- selStats (tostats local_fast_stats) (tostats local_slow_stats) - evalStateT (mapM_ showStat stats) =<< getLocalStatInfo dir +itemInfo :: String -> Annex () +itemInfo p = ifM (isdir p) + ( dirInfo p + , do + v <- Remote.byName' p + case v of + Right r -> remoteInfo r + Left _ -> maybe noinfo (fileInfo p) =<< isAnnexLink p + ) + where + isdir = liftIO . catchBoolIO . (isDirectory <$$> getFileStatus) + noinfo = error $ p ++ " is not a directory or an annexed file or a remote" + +dirInfo :: FilePath -> Annex () +dirInfo dir = showCustom (unwords ["info", dir]) $ do + stats <- selStats (tostats dir_fast_stats) (tostats dir_slow_stats) + evalStateT (mapM_ showStat stats) =<< getDirStatInfo dir return True where - tostats = map (\s -> s dir) + tostats = map (\s -> s dir) + +fileInfo :: FilePath -> Key -> Annex () +fileInfo file k = showCustom (unwords ["info", file]) $ do + evalStateT (mapM_ showStat (file_stats file k)) emptyStatInfo + return True + +remoteInfo :: Remote -> Annex () +remoteInfo r = showCustom (unwords ["info", Remote.name r]) $ do + info <- map (\(k, v) -> simpleStat k (pure v)) <$> Remote.getInfo r + evalStateT (mapM_ showStat (remote_stats r ++ info)) emptyStatInfo + return True selStats :: [Stat] -> [Stat] -> Annex [Stat] selStats fast_stats slow_stats = do @@ -132,22 +159,42 @@ global_slow_stats = , bloom_info , backend_usage ] -local_fast_stats :: [FilePath -> Stat] -local_fast_stats = - [ local_dir +dir_fast_stats :: [FilePath -> Stat] +dir_fast_stats = + [ dir_name , const local_annex_keys , const local_annex_size , const known_annex_files , const known_annex_size ] -local_slow_stats :: [FilePath -> Stat] -local_slow_stats = +dir_slow_stats :: [FilePath -> Stat] +dir_slow_stats = [ const numcopies_stats ] +file_stats :: FilePath -> Key -> [Stat] +file_stats f k = + [ file_name f + , key_size k + , key_name k + ] + +remote_stats :: Remote -> [Stat] +remote_stats r = map (\s -> s r) + [ remote_name + , remote_description + , remote_uuid + , remote_cost + , remote_type + ] + stat :: String -> (String -> StatState String) -> Stat stat desc a = return $ Just (desc, a desc) +-- The json simply contains the same string that is displayed. +simpleStat :: String -> StatState String -> Stat +simpleStat desc getval = stat desc $ json id getval + nostat :: Stat nostat = return Nothing @@ -168,7 +215,7 @@ showStat s = maybe noop calc =<< s lift . showRaw =<< a repository_mode :: Stat -repository_mode = stat "repository mode" $ json id $ lift $ +repository_mode = simpleStat "repository mode" $ lift $ ifM isDirect ( return "direct", return "indirect" ) @@ -181,15 +228,37 @@ remote_list level = stat n $ nojson $ lift $ do where n = showTrustLevel level ++ " repositories" -local_dir :: FilePath -> Stat -local_dir dir = stat "directory" $ json id $ return dir +dir_name :: FilePath -> Stat +dir_name dir = simpleStat "directory" $ pure dir + +file_name :: FilePath -> Stat +file_name file = simpleStat "file" $ pure file + +remote_name :: Remote -> Stat +remote_name r = simpleStat "remote" $ pure (Remote.name r) + +remote_description :: Remote -> Stat +remote_description r = simpleStat "description" $ lift $ + Remote.prettyUUID (Remote.uuid r) + +remote_uuid :: Remote -> Stat +remote_uuid r = simpleStat "uuid" $ pure $ + fromUUID $ Remote.uuid r + +remote_cost :: Remote -> Stat +remote_cost r = simpleStat "cost" $ pure $ + show $ Remote.cost r + +remote_type :: Remote -> Stat +remote_type r = simpleStat "type" $ pure $ + Remote.typename $ Remote.remotetype r local_annex_keys :: Stat local_annex_keys = stat "local annex keys" $ json show $ countKeys <$> cachedPresentData local_annex_size :: Stat -local_annex_size = stat "local annex size" $ json id $ +local_annex_size = simpleStat "local annex size" $ showSizeKeys <$> cachedPresentData known_annex_files :: Stat @@ -197,7 +266,7 @@ known_annex_files = stat "annexed files in working tree" $ json show $ countKeys <$> cachedReferencedData known_annex_size :: Stat -known_annex_size = stat "size of annexed files in working tree" $ json id $ +known_annex_size = simpleStat "size of annexed files in working tree" $ showSizeKeys <$> cachedReferencedData tmp_size :: Stat @@ -206,8 +275,14 @@ tmp_size = staleSize "temporary object directory size" gitAnnexTmpObjectDir bad_data_size :: Stat bad_data_size = staleSize "bad keys size" gitAnnexBadDir +key_size :: Key -> Stat +key_size k = simpleStat "size" $ pure $ showSizeKeys $ foldKeys [k] + +key_name :: Key -> Stat +key_name k = simpleStat "key" $ pure $ key2file k + bloom_info :: Stat -bloom_info = stat "bloom filter size" $ json id $ do +bloom_info = simpleStat "bloom filter size" $ do localkeys <- countKeys <$> cachedPresentData capacity <- fromIntegral <$> lift Command.Unused.bloomCapacity let note = aside $ @@ -240,7 +315,7 @@ transfer_list = stat "transfers in progress" $ nojson $ lift $ do ] disk_size :: Stat -disk_size = stat "available local disk space" $ json id $ lift $ +disk_size = simpleStat "available local disk space" $ lift $ calcfree <$> (annexDiskReserve <$> Annex.getGitConfig) <*> inRepo (getDiskFree . gitAnnexDir) @@ -264,7 +339,7 @@ backend_usage = stat "backend usage" $ nojson $ where calc x y = multiLine $ map (\(n, b) -> b ++ ": " ++ show n) $ - reverse $ sort $ map swap $ M.toList $ + sortBy (flip compare) $ map swap $ M.toList $ M.unionWith (+) x y numcopies_stats :: Stat @@ -273,7 +348,7 @@ numcopies_stats = stat "numcopies stats" $ nojson $ where calc = multiLine . map (\(variance, count) -> show variance ++ ": " ++ show count) - . reverse . sortBy (comparing snd) . M.toList + . sortBy (flip (comparing snd)) . M.toList cachedPresentData :: StatState KeyData cachedPresentData = do @@ -296,12 +371,12 @@ cachedReferencedData = do put s { referencedData = Just v } return v --- currently only available for local info +-- currently only available for directory info cachedNumCopiesStats :: StatState (Maybe NumCopiesStats) cachedNumCopiesStats = numCopiesStats <$> get -getLocalStatInfo :: FilePath -> Annex StatInfo -getLocalStatInfo dir = do +getDirStatInfo :: FilePath -> Annex StatInfo +getDirStatInfo dir = do fast <- Annex.getState Annex.fast matcher <- Limit.getMatcher (presentdata, referenceddata, numcopiesstats) <- |