implemented old Richih wishlist about remote/uuid info
* info: Can now display info about a given uuid. * Added to remote/uuid info: Count of the number of keys present on the remote, and their size. This is rather expensive to calculate, so comes last and --fast will disable it. * Git remote info now includes the date of the last sync with the remote.
This commit is contained in:
parent
c0722eaad1
commit
534c29deae
7 changed files with 81 additions and 16 deletions
|
@ -29,6 +29,7 @@ import Annex.Link
|
||||||
import Types.Key
|
import Types.Key
|
||||||
import Logs.UUID
|
import Logs.UUID
|
||||||
import Logs.Trust
|
import Logs.Trust
|
||||||
|
import Logs.Location
|
||||||
import Config.NumCopies
|
import Config.NumCopies
|
||||||
import Remote
|
import Remote
|
||||||
import Config
|
import Config
|
||||||
|
@ -65,11 +66,12 @@ instance Show Variance where
|
||||||
data StatInfo = StatInfo
|
data StatInfo = StatInfo
|
||||||
{ presentData :: Maybe KeyData
|
{ presentData :: Maybe KeyData
|
||||||
, referencedData :: Maybe KeyData
|
, referencedData :: Maybe KeyData
|
||||||
|
, remoteData :: M.Map UUID KeyData
|
||||||
, numCopiesStats :: Maybe NumCopiesStats
|
, numCopiesStats :: Maybe NumCopiesStats
|
||||||
}
|
}
|
||||||
|
|
||||||
emptyStatInfo :: StatInfo
|
emptyStatInfo :: StatInfo
|
||||||
emptyStatInfo = StatInfo Nothing Nothing Nothing
|
emptyStatInfo = StatInfo Nothing Nothing M.empty 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
|
||||||
|
@ -104,11 +106,17 @@ itemInfo p = ifM (isdir p)
|
||||||
v <- Remote.byName' p
|
v <- Remote.byName' p
|
||||||
case v of
|
case v of
|
||||||
Right r -> remoteInfo r
|
Right r -> remoteInfo r
|
||||||
Left _ -> maybe noinfo (fileInfo p) =<< isAnnexLink p
|
Left _ -> do
|
||||||
|
v' <- Remote.nameToUUID' p
|
||||||
|
liftIO $ print v'
|
||||||
|
case v' of
|
||||||
|
Right u -> uuidInfo u
|
||||||
|
Left _ -> maybe noinfo (fileInfo p)
|
||||||
|
=<< isAnnexLink p
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
isdir = liftIO . catchBoolIO . (isDirectory <$$> getFileStatus)
|
isdir = liftIO . catchBoolIO . (isDirectory <$$> getFileStatus)
|
||||||
noinfo = error $ p ++ " is not a directory or an annexed file or a remote"
|
noinfo = error $ p ++ " is not a directory or an annexed file or a remote or a uuid"
|
||||||
|
|
||||||
dirInfo :: FilePath -> Annex ()
|
dirInfo :: FilePath -> Annex ()
|
||||||
dirInfo dir = showCustom (unwords ["info", dir]) $ do
|
dirInfo dir = showCustom (unwords ["info", dir]) $ do
|
||||||
|
@ -126,7 +134,14 @@ fileInfo file k = showCustom (unwords ["info", file]) $ do
|
||||||
remoteInfo :: Remote -> Annex ()
|
remoteInfo :: Remote -> Annex ()
|
||||||
remoteInfo r = showCustom (unwords ["info", Remote.name r]) $ do
|
remoteInfo r = showCustom (unwords ["info", Remote.name r]) $ do
|
||||||
info <- map (\(k, v) -> simpleStat k (pure v)) <$> Remote.getInfo r
|
info <- map (\(k, v) -> simpleStat k (pure v)) <$> Remote.getInfo r
|
||||||
evalStateT (mapM_ showStat (remote_stats r ++ info)) emptyStatInfo
|
l <- selStats (remote_fast_stats r ++ info) (uuid_slow_stats (Remote.uuid r))
|
||||||
|
evalStateT (mapM_ showStat l) emptyStatInfo
|
||||||
|
return True
|
||||||
|
|
||||||
|
uuidInfo :: UUID -> Annex ()
|
||||||
|
uuidInfo u = showCustom (unwords ["info", fromUUID u]) $ do
|
||||||
|
l <- selStats [] ((uuid_slow_stats u))
|
||||||
|
evalStateT (mapM_ showStat l) emptyStatInfo
|
||||||
return True
|
return True
|
||||||
|
|
||||||
selStats :: [Stat] -> [Stat] -> Annex [Stat]
|
selStats :: [Stat] -> [Stat] -> Annex [Stat]
|
||||||
|
@ -179,8 +194,8 @@ file_stats f k =
|
||||||
, key_name k
|
, key_name k
|
||||||
]
|
]
|
||||||
|
|
||||||
remote_stats :: Remote -> [Stat]
|
remote_fast_stats :: Remote -> [Stat]
|
||||||
remote_stats r = map (\s -> s r)
|
remote_fast_stats r = map (\s -> s r)
|
||||||
[ remote_name
|
[ remote_name
|
||||||
, remote_description
|
, remote_description
|
||||||
, remote_uuid
|
, remote_uuid
|
||||||
|
@ -188,6 +203,12 @@ remote_stats r = map (\s -> s r)
|
||||||
, remote_type
|
, remote_type
|
||||||
]
|
]
|
||||||
|
|
||||||
|
uuid_slow_stats :: UUID -> [Stat]
|
||||||
|
uuid_slow_stats u = map (\s -> s u)
|
||||||
|
[ remote_annex_keys
|
||||||
|
, remote_annex_size
|
||||||
|
]
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
@ -262,6 +283,14 @@ local_annex_size :: Stat
|
||||||
local_annex_size = simpleStat "local annex size" $
|
local_annex_size = simpleStat "local annex size" $
|
||||||
showSizeKeys <$> cachedPresentData
|
showSizeKeys <$> cachedPresentData
|
||||||
|
|
||||||
|
remote_annex_keys :: UUID -> Stat
|
||||||
|
remote_annex_keys u = stat "remote annex keys" $ json show $
|
||||||
|
countKeys <$> cachedRemoteData u
|
||||||
|
|
||||||
|
remote_annex_size :: UUID -> Stat
|
||||||
|
remote_annex_size u = simpleStat "remote annex size" $
|
||||||
|
showSizeKeys <$> cachedRemoteData u
|
||||||
|
|
||||||
known_annex_files :: Stat
|
known_annex_files :: Stat
|
||||||
known_annex_files = stat "annexed files in working tree" $ json show $
|
known_annex_files = stat "annexed files in working tree" $ json show $
|
||||||
countKeys <$> cachedReferencedData
|
countKeys <$> cachedReferencedData
|
||||||
|
@ -361,6 +390,16 @@ cachedPresentData = do
|
||||||
put s { presentData = Just v }
|
put s { presentData = Just v }
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
cachedRemoteData :: UUID -> StatState KeyData
|
||||||
|
cachedRemoteData u = do
|
||||||
|
s <- get
|
||||||
|
case M.lookup u (remoteData s) of
|
||||||
|
Just v -> return v
|
||||||
|
Nothing -> do
|
||||||
|
v <- foldKeys <$> lift (loggedKeysFor u)
|
||||||
|
put s { remoteData = M.insert u v (remoteData s) }
|
||||||
|
return v
|
||||||
|
|
||||||
cachedReferencedData :: StatState KeyData
|
cachedReferencedData :: StatState KeyData
|
||||||
cachedReferencedData = do
|
cachedReferencedData = do
|
||||||
s <- get
|
s <- get
|
||||||
|
@ -383,7 +422,7 @@ getDirStatInfo dir = do
|
||||||
(presentdata, referenceddata, numcopiesstats) <-
|
(presentdata, referenceddata, numcopiesstats) <-
|
||||||
Command.Unused.withKeysFilesReferencedIn dir initial
|
Command.Unused.withKeysFilesReferencedIn dir initial
|
||||||
(update matcher fast)
|
(update matcher fast)
|
||||||
return $ StatInfo (Just presentdata) (Just referenceddata) (Just numcopiesstats)
|
return $ StatInfo (Just presentdata) (Just referenceddata) M.empty (Just numcopiesstats)
|
||||||
where
|
where
|
||||||
initial = (emptyKeyData, emptyKeyData, emptyNumCopiesStats)
|
initial = (emptyKeyData, emptyKeyData, emptyNumCopiesStats)
|
||||||
update matcher fast key file vs@(presentdata, referenceddata, numcopiesstats) =
|
update matcher fast key file vs@(presentdata, referenceddata, numcopiesstats) =
|
||||||
|
|
|
@ -121,7 +121,7 @@ gen' r u c gc = do
|
||||||
, availability = availabilityCalc r
|
, availability = availabilityCalc r
|
||||||
, remotetype = remote
|
, remotetype = remote
|
||||||
, mkUnavailable = return Nothing
|
, mkUnavailable = return Nothing
|
||||||
, getInfo = return $ gitRepoInfo r
|
, getInfo = gitRepoInfo this
|
||||||
, claimUrl = Nothing
|
, claimUrl = Nothing
|
||||||
, checkUrl = Nothing
|
, checkUrl = Nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,7 +159,7 @@ gen r u c gc
|
||||||
, availability = availabilityCalc r
|
, availability = availabilityCalc r
|
||||||
, remotetype = remote
|
, remotetype = remote
|
||||||
, mkUnavailable = unavailable r u c gc
|
, mkUnavailable = unavailable r u c gc
|
||||||
, getInfo = return $ gitRepoInfo r
|
, getInfo = gitRepoInfo new
|
||||||
, claimUrl = Nothing
|
, claimUrl = Nothing
|
||||||
, checkUrl = Nothing
|
, checkUrl = Nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,9 @@ module Remote.Helper.Git where
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import qualified Git
|
import qualified Git
|
||||||
import Types.Availability
|
import Types.Availability
|
||||||
|
import qualified Types.Remote as Remote
|
||||||
|
|
||||||
|
import Data.Time.Clock.POSIX
|
||||||
|
|
||||||
repoCheap :: Git.Repo -> Bool
|
repoCheap :: Git.Repo -> Bool
|
||||||
repoCheap = not . Git.repoIsUrl
|
repoCheap = not . Git.repoIsUrl
|
||||||
|
@ -31,7 +34,15 @@ guardUsable r fallback a
|
||||||
| Git.repoIsLocalUnknown r = fallback
|
| Git.repoIsLocalUnknown r = fallback
|
||||||
| otherwise = a
|
| otherwise = a
|
||||||
|
|
||||||
gitRepoInfo :: Git.Repo -> [(String, String)]
|
gitRepoInfo :: Remote -> Annex [(String, String)]
|
||||||
gitRepoInfo r =
|
gitRepoInfo r = do
|
||||||
[ ("repository location", Git.repoLocation r)
|
d <- fromRepo Git.localGitDir
|
||||||
]
|
mtimes <- liftIO $ mapM (modificationTime <$$> getFileStatus)
|
||||||
|
=<< dirContentsRecursive (d </> "refs" </> "remotes" </> Remote.name r)
|
||||||
|
let lastsynctime = case mtimes of
|
||||||
|
[] -> "never"
|
||||||
|
_ -> show $ posixSecondsToUTCTime $ realToFrac $ maximum mtimes
|
||||||
|
return
|
||||||
|
[ ("repository location", Git.repoLocation (Remote.repo r))
|
||||||
|
, ("last synced", lastsynctime)
|
||||||
|
]
|
||||||
|
|
10
debian/changelog
vendored
10
debian/changelog
vendored
|
@ -1,3 +1,13 @@
|
||||||
|
git-annex (5.20150114) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
|
* info: Can now display info about a given uuid.
|
||||||
|
* Added to remote/uuid info: Count of the number of keys present
|
||||||
|
on the remote, and their size. This is rather expensive to calculate,
|
||||||
|
so comes last and --fast will disable it.
|
||||||
|
* Git remote info now includes the date of the last sync with the remote.
|
||||||
|
|
||||||
|
-- Joey Hess <id@joeyh.name> Tue, 13 Jan 2015 17:03:39 -0400
|
||||||
|
|
||||||
git-annex (5.20150113) unstable; urgency=medium
|
git-annex (5.20150113) unstable; urgency=medium
|
||||||
|
|
||||||
* unlock: Don't allow unlocking files that have never been committed to git
|
* unlock: Don't allow unlocking files that have never been committed to git
|
||||||
|
|
|
@ -696,10 +696,12 @@ 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|file|remote ...]`
|
* `info [directory|file|remote|uuid ...]`
|
||||||
|
|
||||||
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.
|
which can be a directory, or a file, or a remote, 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.
|
||||||
|
|
||||||
|
|
|
@ -6,3 +6,6 @@ It would be nice if I could see that info, preferably with a timestamp telling m
|
||||||
|
|
||||||
Thanks,
|
Thanks,
|
||||||
Richard
|
Richard
|
||||||
|
|
||||||
|
> I left out the stuff that `vicfg` displays. But otherwise
|
||||||
|
> everything mentioned on this page is [[done]]. --[[Joey]]
|
||||||
|
|
Loading…
Reference in a new issue