info: Support being passed a treeish, and show info about the annexed files in it similar to how a directory is handled.
This commit is contained in:
parent
c9c6db5ebc
commit
0e30e71e9c
3 changed files with 84 additions and 23 deletions
|
@ -13,6 +13,8 @@ git-annex (6.20160908) UNRELEASED; urgency=medium
|
||||||
* Improve gpg secret key list parser to deal with changes in gpg 2.1.15.
|
* Improve gpg secret key list parser to deal with changes in gpg 2.1.15.
|
||||||
Fixes key name display in webapp.
|
Fixes key name display in webapp.
|
||||||
* stack.yaml: Update to lts-7.0 (ghc 8)
|
* stack.yaml: Update to lts-7.0 (ghc 8)
|
||||||
|
* info: Support being passed a treeish, and show info about the annexed
|
||||||
|
files in it similar to how a directory is handled.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Thu, 08 Sep 2016 12:48:55 -0400
|
-- Joey Hess <id@joeyh.name> Thu, 08 Sep 2016 12:48:55 -0400
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{- git-annex command
|
{- git-annex command
|
||||||
-
|
-
|
||||||
- Copyright 2011-2014 Joey Hess <id@joeyh.name>
|
- Copyright 2011-2016 Joey Hess <id@joeyh.name>
|
||||||
-
|
-
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
@ -24,6 +24,7 @@ import Utility.DataUnits
|
||||||
import Utility.DiskFree
|
import Utility.DiskFree
|
||||||
import Annex.Content
|
import Annex.Content
|
||||||
import Annex.UUID
|
import Annex.UUID
|
||||||
|
import Annex.CatFile
|
||||||
import Logs.UUID
|
import Logs.UUID
|
||||||
import Logs.Trust
|
import Logs.Trust
|
||||||
import Logs.Location
|
import Logs.Location
|
||||||
|
@ -31,6 +32,7 @@ import Annex.NumCopies
|
||||||
import Remote
|
import Remote
|
||||||
import Config
|
import Config
|
||||||
import Git.Config (boolConfig)
|
import Git.Config (boolConfig)
|
||||||
|
import qualified Git.LsTree as LsTree
|
||||||
import Utility.Percentage
|
import Utility.Percentage
|
||||||
import Types.Transfer
|
import Types.Transfer
|
||||||
import Logs.Transfer
|
import Logs.Transfer
|
||||||
|
@ -136,7 +138,7 @@ itemInfo o p = ifM (isdir p)
|
||||||
Right u -> uuidInfo o u
|
Right u -> uuidInfo o u
|
||||||
Left _ -> ifAnnexed p
|
Left _ -> ifAnnexed p
|
||||||
(fileInfo o p)
|
(fileInfo o p)
|
||||||
(noInfo p)
|
(treeishInfo o p)
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
isdir = liftIO . catchBoolIO . (isDirectory <$$> getFileStatus)
|
isdir = liftIO . catchBoolIO . (isDirectory <$$> getFileStatus)
|
||||||
|
@ -144,17 +146,33 @@ itemInfo o p = ifM (isdir p)
|
||||||
noInfo :: String -> Annex ()
|
noInfo :: String -> Annex ()
|
||||||
noInfo s = do
|
noInfo s = do
|
||||||
showStart "info" s
|
showStart "info" s
|
||||||
showNote $ "not a directory or an annexed file or a remote or a uuid"
|
showNote $ "not a directory or an annexed file or a treeish or a remote or a uuid"
|
||||||
showEndFail
|
showEndFail
|
||||||
|
|
||||||
dirInfo :: InfoOptions -> FilePath -> Annex ()
|
dirInfo :: InfoOptions -> FilePath -> Annex ()
|
||||||
dirInfo o dir = showCustom (unwords ["info", dir]) $ do
|
dirInfo o dir = showCustom (unwords ["info", dir]) $ do
|
||||||
stats <- selStats (tostats dir_fast_stats) (tostats dir_slow_stats)
|
stats <- selStats
|
||||||
|
(tostats (dir_name:tree_fast_stats True))
|
||||||
|
(tostats tree_slow_stats)
|
||||||
evalStateT (mapM_ showStat stats) =<< getDirStatInfo o dir
|
evalStateT (mapM_ showStat stats) =<< getDirStatInfo o dir
|
||||||
return True
|
return True
|
||||||
where
|
where
|
||||||
tostats = map (\s -> s dir)
|
tostats = map (\s -> s dir)
|
||||||
|
|
||||||
|
treeishInfo :: InfoOptions -> String -> Annex ()
|
||||||
|
treeishInfo o t = do
|
||||||
|
mi <- getTreeStatInfo o (Git.Ref t)
|
||||||
|
case mi of
|
||||||
|
Nothing -> noInfo t
|
||||||
|
Just i -> showCustom (unwords ["info", t]) $ do
|
||||||
|
stats <- selStats
|
||||||
|
(tostats (tree_name:tree_fast_stats False))
|
||||||
|
(tostats tree_slow_stats)
|
||||||
|
evalStateT (mapM_ showStat stats) i
|
||||||
|
return True
|
||||||
|
where
|
||||||
|
tostats = map (\s -> s t)
|
||||||
|
|
||||||
fileInfo :: InfoOptions -> FilePath -> Key -> Annex ()
|
fileInfo :: InfoOptions -> FilePath -> Key -> Annex ()
|
||||||
fileInfo o file k = showCustom (unwords ["info", file]) $ do
|
fileInfo o file k = showCustom (unwords ["info", file]) $ do
|
||||||
evalStateT (mapM_ showStat (file_stats file k)) (emptyStatInfo o)
|
evalStateT (mapM_ showStat (file_stats file k)) (emptyStatInfo o)
|
||||||
|
@ -192,27 +210,29 @@ global_fast_stats =
|
||||||
, transfer_list
|
, transfer_list
|
||||||
, disk_size
|
, disk_size
|
||||||
]
|
]
|
||||||
|
|
||||||
global_slow_stats :: [Stat]
|
global_slow_stats :: [Stat]
|
||||||
global_slow_stats =
|
global_slow_stats =
|
||||||
[ tmp_size
|
[ tmp_size
|
||||||
, bad_data_size
|
, bad_data_size
|
||||||
, local_annex_keys
|
, local_annex_keys
|
||||||
, local_annex_size
|
, local_annex_size
|
||||||
, known_annex_files
|
, known_annex_files True
|
||||||
, known_annex_size
|
, known_annex_size True
|
||||||
, bloom_info
|
, bloom_info
|
||||||
, backend_usage
|
, backend_usage
|
||||||
]
|
]
|
||||||
dir_fast_stats :: [FilePath -> Stat]
|
|
||||||
dir_fast_stats =
|
tree_fast_stats :: Bool -> [FilePath -> Stat]
|
||||||
[ dir_name
|
tree_fast_stats isworktree =
|
||||||
, const local_annex_keys
|
[ const local_annex_keys
|
||||||
, const local_annex_size
|
, const local_annex_size
|
||||||
, const known_annex_files
|
, const (known_annex_files isworktree)
|
||||||
, const known_annex_size
|
, const (known_annex_size isworktree)
|
||||||
]
|
]
|
||||||
dir_slow_stats :: [FilePath -> Stat]
|
|
||||||
dir_slow_stats =
|
tree_slow_stats :: [FilePath -> Stat]
|
||||||
|
tree_slow_stats =
|
||||||
[ const numcopies_stats
|
[ const numcopies_stats
|
||||||
, const reposizes_stats
|
, const reposizes_stats
|
||||||
]
|
]
|
||||||
|
@ -295,6 +315,9 @@ countRepoList n s = show n ++ "\n" ++ beginning s
|
||||||
dir_name :: FilePath -> Stat
|
dir_name :: FilePath -> Stat
|
||||||
dir_name dir = simpleStat "directory" $ pure dir
|
dir_name dir = simpleStat "directory" $ pure dir
|
||||||
|
|
||||||
|
tree_name :: String -> Stat
|
||||||
|
tree_name t = simpleStat "tree" $ pure t
|
||||||
|
|
||||||
file_name :: FilePath -> Stat
|
file_name :: FilePath -> Stat
|
||||||
file_name file = simpleStat "file" $ pure file
|
file_name file = simpleStat "file" $ pure file
|
||||||
|
|
||||||
|
@ -337,13 +360,19 @@ remote_annex_size :: UUID -> Stat
|
||||||
remote_annex_size u = simpleStat "remote annex size" $
|
remote_annex_size u = simpleStat "remote annex size" $
|
||||||
showSizeKeys =<< cachedRemoteData u
|
showSizeKeys =<< cachedRemoteData u
|
||||||
|
|
||||||
known_annex_files :: Stat
|
known_annex_files :: Bool -> Stat
|
||||||
known_annex_files = stat "annexed files in working tree" $ json show $
|
known_annex_files isworktree =
|
||||||
countKeys <$> cachedReferencedData
|
stat ("annexed files in " ++ treeDesc isworktree) $ json show $
|
||||||
|
countKeys <$> cachedReferencedData
|
||||||
|
|
||||||
known_annex_size :: Stat
|
known_annex_size :: Bool -> Stat
|
||||||
known_annex_size = simpleStat "size of annexed files in working tree" $
|
known_annex_size isworktree =
|
||||||
showSizeKeys =<< cachedReferencedData
|
simpleStat ("size of annexed files in " ++ treeDesc isworktree) $
|
||||||
|
showSizeKeys =<< cachedReferencedData
|
||||||
|
|
||||||
|
treeDesc :: Bool -> String
|
||||||
|
treeDesc True = "working tree"
|
||||||
|
treeDesc False = "tree"
|
||||||
|
|
||||||
tmp_size :: Stat
|
tmp_size :: Stat
|
||||||
tmp_size = staleSize "temporary object directory size" gitAnnexTmpObjectDir
|
tmp_size = staleSize "temporary object directory size" gitAnnexTmpObjectDir
|
||||||
|
@ -523,6 +552,36 @@ getDirStatInfo o dir = do
|
||||||
, return vs
|
, return vs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
getTreeStatInfo :: InfoOptions -> Git.Ref -> Annex (Maybe StatInfo)
|
||||||
|
getTreeStatInfo o r = do
|
||||||
|
fast <- Annex.getState Annex.fast
|
||||||
|
(ls, cleanup) <- inRepo $ LsTree.lsTree r
|
||||||
|
(presentdata, referenceddata, repodata) <- go fast ls initial
|
||||||
|
ifM (liftIO cleanup)
|
||||||
|
( return $ Just $
|
||||||
|
StatInfo (Just presentdata) (Just referenceddata) repodata Nothing o
|
||||||
|
, return Nothing
|
||||||
|
)
|
||||||
|
where
|
||||||
|
initial = (emptyKeyData, emptyKeyData, M.empty)
|
||||||
|
go _ [] vs = return vs
|
||||||
|
go fast (l:ls) vs@(presentdata, referenceddata, repodata) = do
|
||||||
|
mk <- catKey (LsTree.sha l)
|
||||||
|
case mk of
|
||||||
|
Nothing -> go fast ls vs
|
||||||
|
Just key -> do
|
||||||
|
!presentdata' <- ifM (inAnnex key)
|
||||||
|
( return $ addKey key presentdata
|
||||||
|
, return presentdata
|
||||||
|
)
|
||||||
|
let !referenceddata' = addKey key referenceddata
|
||||||
|
!repodata' <- if fast
|
||||||
|
then return repodata
|
||||||
|
else do
|
||||||
|
locs <- Remote.keyLocations key
|
||||||
|
return (updateRepoData key locs repodata)
|
||||||
|
go fast ls $! (presentdata', referenceddata', repodata')
|
||||||
|
|
||||||
emptyKeyData :: KeyData
|
emptyKeyData :: KeyData
|
||||||
emptyKeyData = KeyData 0 0 0 M.empty
|
emptyKeyData = KeyData 0 0 0 M.empty
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,13 @@ git-annex info - shows information about the specified item or the repository as
|
||||||
|
|
||||||
# SYNOPSIS
|
# SYNOPSIS
|
||||||
|
|
||||||
git annex info `[directory|file|remote|uuid ...]`
|
git annex info `[directory|file|treeish|remote|uuid ...]`
|
||||||
|
|
||||||
# DESCRIPTION
|
# DESCRIPTION
|
||||||
|
|
||||||
Displays statistics and other information for the specified item,
|
Displays statistics and other information for the specified item,
|
||||||
which can be a directory, or a file, or a remote, or the uuid of a
|
which can be a directory, or a file, or a treeish, or a remote,
|
||||||
repository.
|
or the uuid of a repository.
|
||||||
|
|
||||||
When no item is specified, displays statistics and information
|
When no item is specified, displays statistics and information
|
||||||
for the repository as a whole.
|
for the repository as a whole.
|
||||||
|
|
Loading…
Add table
Reference in a new issue