summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-01-13 18:11:03 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-01-13 18:13:14 -0400
commitde9ead9b92091e07795acf003dc05adb6912f15c (patch)
tree0ed928581ee2634134944e71cb87d6823d60733d
parente77d599e8f5167319b7624226dca02cfe0c65a77 (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.
-rw-r--r--Command/Info.hs55
-rw-r--r--Remote/GCrypt.hs2
-rw-r--r--Remote/Git.hs2
-rw-r--r--Remote/Helper/Git.hs19
-rw-r--r--debian/changelog10
-rw-r--r--doc/git-annex.mdwn6
-rw-r--r--doc/todo/wishlist:_git_annex_info_UUID.mdwn3
7 files changed, 81 insertions, 16 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) =
diff --git a/Remote/GCrypt.hs b/Remote/GCrypt.hs
index 2f2ddc9f3..6bf7f89f5 100644
--- a/Remote/GCrypt.hs
+++ b/Remote/GCrypt.hs
@@ -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
}
diff --git a/Remote/Git.hs b/Remote/Git.hs
index 17b44fa6e..f015e295e 100644
--- a/Remote/Git.hs
+++ b/Remote/Git.hs
@@ -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
}
diff --git a/Remote/Helper/Git.hs b/Remote/Helper/Git.hs
index 156d7ac28..9ed27ac8b 100644
--- a/Remote/Helper/Git.hs
+++ b/Remote/Helper/Git.hs
@@ -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)
+ ]
diff --git a/debian/changelog b/debian/changelog
index 143149428..0db52be87 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -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
diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn
index ce0311e46..74ce72137 100644
--- a/doc/git-annex.mdwn
+++ b/doc/git-annex.mdwn
@@ -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.
diff --git a/doc/todo/wishlist:_git_annex_info_UUID.mdwn b/doc/todo/wishlist:_git_annex_info_UUID.mdwn
index 0d1270e1e..5b9633e18 100644
--- a/doc/todo/wishlist:_git_annex_info_UUID.mdwn
+++ b/doc/todo/wishlist:_git_annex_info_UUID.mdwn
@@ -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]]