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 Logs.UUID
|
||||
import Logs.Trust
|
||||
import Logs.Location
|
||||
import Config.NumCopies
|
||||
import Remote
|
||||
import Config
|
||||
|
@ -65,11 +66,12 @@ instance Show Variance where
|
|||
data StatInfo = StatInfo
|
||||
{ presentData :: Maybe KeyData
|
||||
, referencedData :: Maybe KeyData
|
||||
, remoteData :: M.Map UUID KeyData
|
||||
, numCopiesStats :: Maybe NumCopiesStats
|
||||
}
|
||||
|
||||
|
||||
emptyStatInfo :: StatInfo
|
||||
emptyStatInfo = StatInfo Nothing Nothing Nothing
|
||||
emptyStatInfo = StatInfo Nothing Nothing M.empty Nothing
|
||||
|
||||
-- a state monad for running Stats in
|
||||
type StatState = StateT StatInfo Annex
|
||||
|
@ -104,11 +106,17 @@ itemInfo p = ifM (isdir p)
|
|||
v <- Remote.byName' p
|
||||
case v of
|
||||
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
|
||||
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 dir = showCustom (unwords ["info", dir]) $ do
|
||||
|
@ -126,7 +134,14 @@ fileInfo file k = showCustom (unwords ["info", file]) $ do
|
|||
remoteInfo :: Remote -> Annex ()
|
||||
remoteInfo r = showCustom (unwords ["info", Remote.name r]) $ do
|
||||
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
|
||||
|
||||
selStats :: [Stat] -> [Stat] -> Annex [Stat]
|
||||
|
@ -179,8 +194,8 @@ file_stats f k =
|
|||
, key_name k
|
||||
]
|
||||
|
||||
remote_stats :: Remote -> [Stat]
|
||||
remote_stats r = map (\s -> s r)
|
||||
remote_fast_stats :: Remote -> [Stat]
|
||||
remote_fast_stats r = map (\s -> s r)
|
||||
[ remote_name
|
||||
, remote_description
|
||||
, remote_uuid
|
||||
|
@ -188,6 +203,12 @@ remote_stats r = map (\s -> s r)
|
|||
, 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 desc a = return $ Just (desc, a desc)
|
||||
|
||||
|
@ -262,6 +283,14 @@ local_annex_size :: Stat
|
|||
local_annex_size = simpleStat "local annex size" $
|
||||
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 "annexed files in working tree" $ json show $
|
||||
countKeys <$> cachedReferencedData
|
||||
|
@ -361,6 +390,16 @@ cachedPresentData = do
|
|||
put s { presentData = Just 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 = do
|
||||
s <- get
|
||||
|
@ -383,7 +422,7 @@ getDirStatInfo dir = do
|
|||
(presentdata, referenceddata, numcopiesstats) <-
|
||||
Command.Unused.withKeysFilesReferencedIn dir initial
|
||||
(update matcher fast)
|
||||
return $ StatInfo (Just presentdata) (Just referenceddata) (Just numcopiesstats)
|
||||
return $ StatInfo (Just presentdata) (Just referenceddata) M.empty (Just numcopiesstats)
|
||||
where
|
||||
initial = (emptyKeyData, emptyKeyData, emptyNumCopiesStats)
|
||||
update matcher fast key file vs@(presentdata, referenceddata, numcopiesstats) =
|
||||
|
|
|
@ -121,7 +121,7 @@ gen' r u c gc = do
|
|||
, availability = availabilityCalc r
|
||||
, remotetype = remote
|
||||
, mkUnavailable = return Nothing
|
||||
, getInfo = return $ gitRepoInfo r
|
||||
, getInfo = gitRepoInfo this
|
||||
, claimUrl = Nothing
|
||||
, checkUrl = Nothing
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ gen r u c gc
|
|||
, availability = availabilityCalc r
|
||||
, remotetype = remote
|
||||
, mkUnavailable = unavailable r u c gc
|
||||
, getInfo = return $ gitRepoInfo r
|
||||
, getInfo = gitRepoInfo new
|
||||
, claimUrl = Nothing
|
||||
, checkUrl = Nothing
|
||||
}
|
||||
|
|
|
@ -10,6 +10,9 @@ module Remote.Helper.Git where
|
|||
import Common.Annex
|
||||
import qualified Git
|
||||
import Types.Availability
|
||||
import qualified Types.Remote as Remote
|
||||
|
||||
import Data.Time.Clock.POSIX
|
||||
|
||||
repoCheap :: Git.Repo -> Bool
|
||||
repoCheap = not . Git.repoIsUrl
|
||||
|
@ -31,7 +34,15 @@ guardUsable r fallback a
|
|||
| Git.repoIsLocalUnknown r = fallback
|
||||
| otherwise = a
|
||||
|
||||
gitRepoInfo :: Git.Repo -> [(String, String)]
|
||||
gitRepoInfo r =
|
||||
[ ("repository location", Git.repoLocation r)
|
||||
]
|
||||
gitRepoInfo :: Remote -> Annex [(String, String)]
|
||||
gitRepoInfo r = do
|
||||
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
|
||||
|
||||
* 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,
|
||||
specify `--gource`.
|
||||
|
||||
* `info [directory|file|remote ...]`
|
||||
* `info [directory|file|remote|uuid ...]`
|
||||
|
||||
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
|
||||
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,
|
||||
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