speed hack

Avoids the external program being started just to use LISTCONFIGS on an
already accepted config.

So initremote/enableremote will still run the external program an extra
time to use LISTCONFIGS, but everything that uses the special remote after
it's initialized will not any longer.
This commit is contained in:
Joey Hess 2020-01-17 17:23:19 -04:00
parent b1c224dd48
commit 8406ff8861
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -177,7 +177,7 @@ externalSetup _ mu _ c gc = do
-- Now that we have an external, ask it to LISTCONFIGS, -- Now that we have an external, ask it to LISTCONFIGS,
-- and re-parse the RemoteConfig strictly, so we can -- and re-parse the RemoteConfig strictly, so we can
-- error out if the user provided an unexpected config. -- error out if the user provided an unexpected config.
either giveup return . parseRemoteConfig c' _ <- either giveup return . parseRemoteConfig c'
=<< strictRemoteConfigParser external =<< strictRemoteConfigParser external
handleRequest external INITREMOTE Nothing $ \resp -> case resp of handleRequest external INITREMOTE Nothing $ \resp -> case resp of
INITREMOTE_SUCCESS -> result () INITREMOTE_SUCCESS -> result ()
@ -816,8 +816,11 @@ listConfigs external = handleRequest external LISTCONFIGS Nothing (collect [])
remoteConfigParser :: RemoteConfig -> Annex RemoteConfigParser remoteConfigParser :: RemoteConfig -> Annex RemoteConfigParser
remoteConfigParser c remoteConfigParser c
-- No need to ask when there is no config to parse. -- No need to start the external when there is no config to parse,
| M.null c = return lenientRemoteConfigParser -- or when everything in the config was already accepted; in those
-- cases the lenient parser will do the same thing as the strict
-- parser.
| M.null (M.filter isproposed c) = return lenientRemoteConfigParser
| otherwise = case parseRemoteConfig c lenientRemoteConfigParser of | otherwise = case parseRemoteConfig c lenientRemoteConfigParser of
Left _ -> return lenientRemoteConfigParser Left _ -> return lenientRemoteConfigParser
Right pc -> case (getRemoteConfigValue externaltypeField pc, getRemoteConfigValue readonlyField pc) of Right pc -> case (getRemoteConfigValue externaltypeField pc, getRemoteConfigValue readonlyField pc) of
@ -826,3 +829,6 @@ remoteConfigParser c
(Just externaltype, _) -> do (Just externaltype, _) -> do
external <- newExternal externaltype Nothing pc Nothing Nothing external <- newExternal externaltype Nothing pc Nothing Nothing
strictRemoteConfigParser external strictRemoteConfigParser external
where
isproposed (Accepted _) = False
isproposed (Proposed _) = True