diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-01-13 18:11:03 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-01-13 18:13:14 -0400 |
commit | de9ead9b92091e07795acf003dc05adb6912f15c (patch) | |
tree | 0ed928581ee2634134944e71cb87d6823d60733d /Command | |
parent | e77d599e8f5167319b7624226dca02cfe0c65a77 (diff) |
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.
Diffstat (limited to 'Command')
-rw-r--r-- | Command/Info.hs | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/Command/Info.hs b/Command/Info.hs index 9356830e0..36d93a270 100644 --- a/Command/Info.hs +++ b/Command/Info.hs @@ -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) = |