From f8dd20a34d7851d7e3827387d323ffab585a25a2 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 26 Dec 2013 18:23:13 -0400 Subject: external special remotes mostly implemented (untested) This has not been tested at all. It compiles! The only known missing things are support for encryption, and for get/set of special remote configuration, and of key state. (The latter needs separate work to add a new per-key log file to store that state.) Only thing I don't much like is that initremote needs to be passed both type=external and externaltype=foo. It would be better to have just type=foo Most of this is quite straightforward code, that largely wrote itself given the types. The only tricky parts were: * Need to lock the remote when using it to eg make a request, because in theory git-annex could have multiple threads that each try to use a remote at the same time. I don't think that git-annex ever does that currently, but better safe than sorry. * Rather than starting up every external special remote program when git-annex starts, they are started only on demand, when first used. This will avoid slowdown, especially when running fast git-annex query commands. Once started, they keep running until git-annex stops, currently, which may not be ideal, but it's hard to know a better time to stop them. * Bit of a chicken and egg problem with caching the cost of the remote, because setting annex-cost in the git config needs the remote to already be set up. Managed to finesse that. This commit was sponsored by Lukas Anzinger. --- Config.hs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'Config.hs') diff --git a/Config.hs b/Config.hs index 0c6b64f50..3c6f3faa1 100644 --- a/Config.hs +++ b/Config.hs @@ -12,7 +12,6 @@ import qualified Git import qualified Git.Config import qualified Git.Command import qualified Annex -import qualified Types.Remote as Remote import Config.Cost type UnqualifiedConfigKey = String @@ -55,14 +54,16 @@ annexConfig key = ConfigKey $ "annex." ++ key - by remote..annex-cost, or if remote..annex-cost-command - is set and prints a number, that is used. -} remoteCost :: RemoteGitConfig -> Cost -> Annex Cost -remoteCost c def = case remoteAnnexCostCommand c of +remoteCost c def = fromMaybe def <$> remoteCost' c + +remoteCost' :: RemoteGitConfig -> Annex (Maybe Cost) +remoteCost' c = case remoteAnnexCostCommand c of Just cmd | not (null cmd) -> liftIO $ - (fromMaybe def . readish) <$> - readProcess "sh" ["-c", cmd] - _ -> return $ fromMaybe def $ remoteAnnexCost c + readish <$> readProcess "sh" ["-c", cmd] + _ -> return $ remoteAnnexCost c -setRemoteCost :: Remote -> Cost -> Annex () -setRemoteCost r c = setConfig (remoteConfig (Remote.repo r) "cost") (show c) +setRemoteCost :: Git.Repo -> Cost -> Annex () +setRemoteCost r c = setConfig (remoteConfig r "cost") (show c) getNumCopies :: Maybe Int -> Annex Int getNumCopies (Just v) = return v -- cgit v1.2.3