From aff377f1fd40d1d5dbfc44e9a3ca37e646c1dcd4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 9 Jan 2018 15:36:56 -0400 Subject: Improve startup time for commands that do not operate on remotes And for tab completion, by not unnessessarily statting paths to remotes, which used to cause eg, spin-up of removable drives. Got rid of the remotes member of Git.Repo. This was a bit painful. Remote.Git modifies the list of remotes as it reads their configs, so still need a persistent list of remotes. So, put it in as Annex.gitremotes. It's only populated by getGitRemotes, so commands like examinekey that don't care about remotes won't do so. This commit was sponsored by Jake Vosloo on Patreon. --- Annex.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'Annex.hs') diff --git a/Annex.hs b/Annex.hs index 427c479d8..4ab700332 100644 --- a/Annex.hs +++ b/Annex.hs @@ -1,6 +1,6 @@ {- git-annex monad - - - Copyright 2010-2013 Joey Hess + - Copyright 2010-2018 Joey Hess - - Licensed under the GNU GPL version 3 or higher. -} @@ -34,12 +34,14 @@ module Annex ( getRemoteGitConfig, withCurrentState, changeDirectory, + getGitRemotes, incError, ) where import Common import qualified Git import qualified Git.Config +import qualified Git.Construct import Annex.Fixup import Git.CatFile import Git.HashObject @@ -98,6 +100,7 @@ data AnnexState = AnnexState { repo :: Git.Repo , repoadjustment :: (Git.Repo -> IO Git.Repo) , gitconfig :: GitConfig + , gitremotes :: Maybe [Git.Repo] , backend :: Maybe (BackendA Annex) , remotes :: [Types.Remote.RemoteA Annex] , remoteannexstate :: M.Map UUID AnnexState @@ -153,6 +156,7 @@ newState c r = do { repo = r , repoadjustment = return , gitconfig = c + , gitremotes = Nothing , backend = Nothing , remotes = [] , remoteannexstate = M.empty @@ -357,3 +361,13 @@ incError = changeState $ \s -> let ! c = errcounter s + 1 ! s' = s { errcounter = c } in s' + +getGitRemotes :: Annex [Git.Repo] +getGitRemotes = do + s <- getState id + case gitremotes s of + Just rs -> return rs + Nothing -> do + rs <- liftIO $ Git.Construct.fromRemotes (repo s) + changeState $ \s' -> s' { gitremotes = Just rs } + return rs -- cgit v1.2.3