summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-10-21 13:24:15 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-10-21 13:24:15 -0400
commit025c8e0d6e4c0037296968a828a6b57148f8e5e5 (patch)
treef72451234388b895e2b7387a030e69dbd0e98ac2
parent477f350c878a4288bba3485b59b675a80386eda6 (diff)
info: When run on a single annexed file, displays some info about the file, including its key and size.
-rw-r--r--Command/Info.hs68
-rw-r--r--debian/changelog2
-rw-r--r--doc/git-annex.mdwn14
3 files changed, 58 insertions, 26 deletions
diff --git a/Command/Info.hs b/Command/Info.hs
index 68ac607d9..ffa6a591e 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.
-}
@@ -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) <-
diff --git a/debian/changelog b/debian/changelog
index c37c303a4..6b3b59b83 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -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
diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn
index 011b6d91f..95d8e14c5 100644
--- a/doc/git-annex.mdwn
+++ b/doc/git-annex.mdwn
@@ -676,17 +676,15 @@ 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.
- To only show the data that can be gathered quickly, use `--fast`.
+ 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.
- 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.
+ To only show the data that can be gathered quickly, use `--fast`.
For example, suppose you want to run "git annex get .", but
would first like to see how much disk space that will use.