info: When run on a single annexed file, displays some info about the file, including its key and size.

This commit is contained in:
Joey Hess 2014-10-21 13:24:15 -04:00
parent 91b2b3a817
commit 4a9e70c705
3 changed files with 58 additions and 26 deletions

View file

@ -1,6 +1,6 @@
{- git-annex command {- 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. - Licensed under the GNU GPL version 3 or higher.
-} -}
@ -24,6 +24,7 @@ import Command
import Utility.DataUnits import Utility.DataUnits
import Utility.DiskFree import Utility.DiskFree
import Annex.Content import Annex.Content
import Annex.Link
import Types.Key import Types.Key
import Logs.UUID import Logs.UUID
import Logs.Trust import Logs.Trust
@ -65,6 +66,9 @@ data StatInfo = StatInfo
, referencedData :: Maybe KeyData , referencedData :: Maybe KeyData
, numCopiesStats :: Maybe NumCopiesStats , numCopiesStats :: Maybe NumCopiesStats
} }
emptyStatInfo :: StatInfo
emptyStatInfo = StatInfo Nothing Nothing Nothing
-- a state monad for running Stats in -- a state monad for running Stats in
type StatState = StateT StatInfo Annex type StatState = StateT StatInfo Annex
@ -72,36 +76,48 @@ type StatState = StateT StatInfo Annex
cmd :: [Command] cmd :: [Command]
cmd = [noCommit $ dontCheck repoExists $ withOptions [jsonOption] $ cmd = [noCommit $ dontCheck repoExists $ withOptions [jsonOption] $
command "info" paramPaths seek SectionQuery command "info" paramPaths seek SectionQuery
"shows general information about the annex"] "shows information about the specified item or the repository as a whole"]
seek :: CommandSeek seek :: CommandSeek
seek = withWords start seek = withWords start
start :: [FilePath] -> CommandStart start :: [String] -> CommandStart
start [] = do start [] = do
globalInfo globalInfo
stop stop
start ps = do start ps = do
mapM_ localInfo =<< filterM isdir ps mapM_ itemInfo ps
stop stop
where
isdir = liftIO . catchBoolIO . (isDirectory <$$> getFileStatus)
globalInfo :: Annex () globalInfo :: Annex ()
globalInfo = do globalInfo = do
stats <- selStats global_fast_stats global_slow_stats stats <- selStats global_fast_stats global_slow_stats
showCustom "info" $ do showCustom "info" $ do
evalStateT (mapM_ showStat stats) (StatInfo Nothing Nothing Nothing) evalStateT (mapM_ showStat stats) emptyStatInfo
return True return True
localInfo :: FilePath -> Annex () itemInfo :: String -> Annex ()
localInfo dir = showCustom (unwords ["info", dir]) $ do itemInfo p = ifM (isdir p)
stats <- selStats (tostats local_fast_stats) (tostats local_slow_stats) ( dirInfo p
evalStateT (mapM_ showStat stats) =<< getLocalStatInfo dir , maybe noinfo (fileInfo p) =<< isAnnexLink p
)
where
isdir = liftIO . catchBoolIO . (isDirectory <$$> getFileStatus)
noinfo = error $ p ++ " is not a directory or an annexed file"
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 return True
where 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
selStats :: [Stat] -> [Stat] -> Annex [Stat] selStats :: [Stat] -> [Stat] -> Annex [Stat]
selStats fast_stats slow_stats = do selStats fast_stats slow_stats = do
fast <- Annex.getState Annex.fast fast <- Annex.getState Annex.fast
@ -132,19 +148,26 @@ global_slow_stats =
, bloom_info , bloom_info
, backend_usage , backend_usage
] ]
local_fast_stats :: [FilePath -> Stat] dir_fast_stats :: [FilePath -> Stat]
local_fast_stats = dir_fast_stats =
[ local_dir [ local_dir
, const local_annex_keys , const local_annex_keys
, const local_annex_size , const local_annex_size
, const known_annex_files , const known_annex_files
, const known_annex_size , const known_annex_size
] ]
local_slow_stats :: [FilePath -> Stat] dir_slow_stats :: [FilePath -> Stat]
local_slow_stats = dir_slow_stats =
[ const numcopies_stats [ const numcopies_stats
] ]
file_stats :: FilePath -> Key -> [Stat]
file_stats f k =
[ local_file f
, key_size k
, key_name k
]
stat :: String -> (String -> StatState String) -> Stat stat :: String -> (String -> StatState String) -> Stat
stat desc a = return $ Just (desc, a desc) stat desc a = return $ Just (desc, a desc)
@ -184,6 +207,9 @@ remote_list level = stat n $ nojson $ lift $ do
local_dir :: FilePath -> Stat local_dir :: FilePath -> Stat
local_dir dir = stat "directory" $ json id $ return dir local_dir dir = stat "directory" $ json id $ return dir
local_file :: FilePath -> Stat
local_file file = stat "file" $ json id $ return file
local_annex_keys :: Stat local_annex_keys :: Stat
local_annex_keys = stat "local annex keys" $ json show $ local_annex_keys = stat "local annex keys" $ json show $
countKeys <$> cachedPresentData countKeys <$> cachedPresentData
@ -206,6 +232,12 @@ tmp_size = staleSize "temporary object directory size" gitAnnexTmpObjectDir
bad_data_size :: Stat bad_data_size :: Stat
bad_data_size = staleSize "bad keys size" gitAnnexBadDir bad_data_size = staleSize "bad keys size" gitAnnexBadDir
key_size :: Key -> Stat
key_size k = stat "size" $ json id $ pure $ showSizeKeys $ foldKeys [k]
key_name :: Key -> Stat
key_name k = stat "key" $ json id $ pure $ key2file k
bloom_info :: Stat bloom_info :: Stat
bloom_info = stat "bloom filter size" $ json id $ do bloom_info = stat "bloom filter size" $ json id $ do
localkeys <- countKeys <$> cachedPresentData localkeys <- countKeys <$> cachedPresentData
@ -296,12 +328,12 @@ cachedReferencedData = do
put s { referencedData = Just v } put s { referencedData = Just v }
return v return v
-- currently only available for local info -- currently only available for directory info
cachedNumCopiesStats :: StatState (Maybe NumCopiesStats) cachedNumCopiesStats :: StatState (Maybe NumCopiesStats)
cachedNumCopiesStats = numCopiesStats <$> get cachedNumCopiesStats = numCopiesStats <$> get
getLocalStatInfo :: FilePath -> Annex StatInfo getDirStatInfo :: FilePath -> Annex StatInfo
getLocalStatInfo dir = do getDirStatInfo dir = do
fast <- Annex.getState Annex.fast fast <- Annex.getState Annex.fast
matcher <- Limit.getMatcher matcher <- Limit.getMatcher
(presentdata, referenceddata, numcopiesstats) <- (presentdata, referenceddata, numcopiesstats) <-

2
debian/changelog vendored
View file

@ -11,6 +11,8 @@ git-annex (5.20141014) UNRELEASED; urgency=medium
making git-annex not re-exec itself on start on windows, and making the making git-annex not re-exec itself on start on windows, and making the
test suite on Windows run tests without forking. test suite on Windows run tests without forking.
* glacier: Fix pipe setup when calling glacier-cli to retrieve an object. * glacier: Fix pipe setup when calling glacier-cli to retrieve an object.
* info: When run on a single annexed file, displays some info about the
file, including its key and size.
-- Joey Hess <joeyh@debian.org> Tue, 14 Oct 2014 14:09:24 -0400 -- Joey Hess <joeyh@debian.org> Tue, 14 Oct 2014 14:09:24 -0400

View file

@ -676,18 +676,16 @@ subdirectories).
To generate output suitable for the gource visualization program, To generate output suitable for the gource visualization program,
specify `--gource`. specify `--gource`.
* `info [directory ...]` * `info [directory|file ...]`
Displays some statistics and other information, including how much data Displays statistics and other information for the specified item,
is in the annex and a list of all known repositories. or if none is specified, for the repository as a whole.
When a directory is specified, the file matching options can be used
to select the files in the directory that are included in the statistics.
To only show the data that can be gathered quickly, use `--fast`. To only show the data that can be gathered quickly, use `--fast`.
When a directory is specified, shows a differently formatted info
display for that directory. In this mode, all of the matching
options can be used to filter the files that will be included in
the information.
For example, suppose you want to run "git annex get .", but For example, suppose you want to run "git annex get .", but
would first like to see how much disk space that will use. would first like to see how much disk space that will use.
Then run: Then run: