info: When run on a single annexed file, displays some info about the file, including its key and size.
This commit is contained in:
parent
91b2b3a817
commit
4a9e70c705
3 changed files with 58 additions and 26 deletions
|
@ -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.
|
||||
-}
|
||||
|
@ -24,6 +24,7 @@ import Command
|
|||
import Utility.DataUnits
|
||||
import Utility.DiskFree
|
||||
import Annex.Content
|
||||
import Annex.Link
|
||||
import Types.Key
|
||||
import Logs.UUID
|
||||
import Logs.Trust
|
||||
|
@ -65,6 +66,9 @@ 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
|
||||
|
@ -72,36 +76,48 @@ type StatState = StateT StatInfo Annex
|
|||
cmd :: [Command]
|
||||
cmd = [noCommit $ dontCheck repoExists $ withOptions [jsonOption] $
|
||||
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 = 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
|
||||
, 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
|
||||
where
|
||||
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 fast_stats slow_stats = do
|
||||
fast <- Annex.getState Annex.fast
|
||||
|
@ -132,19 +148,26 @@ global_slow_stats =
|
|||
, bloom_info
|
||||
, backend_usage
|
||||
]
|
||||
local_fast_stats :: [FilePath -> Stat]
|
||||
local_fast_stats =
|
||||
dir_fast_stats :: [FilePath -> Stat]
|
||||
dir_fast_stats =
|
||||
[ local_dir
|
||||
, 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 =
|
||||
[ local_file f
|
||||
, key_size k
|
||||
, key_name k
|
||||
]
|
||||
|
||||
stat :: String -> (String -> StatState String) -> Stat
|
||||
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 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" $ json show $
|
||||
countKeys <$> cachedPresentData
|
||||
|
@ -206,6 +232,12 @@ 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 = 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 filter size" $ json id $ do
|
||||
localkeys <- countKeys <$> cachedPresentData
|
||||
|
@ -296,12 +328,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) <-
|
||||
|
|
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -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
|
||||
test suite on Windows run tests without forking.
|
||||
* 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
|
||||
|
||||
|
|
|
@ -676,18 +676,16 @@ subdirectories).
|
|||
To generate output suitable for the gource visualization program,
|
||||
specify `--gource`.
|
||||
|
||||
* `info [directory ...]`
|
||||
* `info [directory|file ...]`
|
||||
|
||||
Displays some statistics and other information, including how much data
|
||||
is in the annex and a list of all known repositories.
|
||||
Displays statistics and other information for the specified item,
|
||||
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`.
|
||||
|
||||
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
|
||||
would first like to see how much disk space that will use.
|
||||
Then run:
|
||||
|
|
Loading…
Reference in a new issue