summaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-08-17 12:26:14 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-08-17 13:54:14 -0400
commitda0a1360d7b57d034620338996552752ab873045 (patch)
tree7cd5d994f15ae0d52e18321a129360b9e39a6d7d /Command
parent13ce429b5cbc3036e24613ce85e17af7acd9a480 (diff)
add annex-ignore-command and annex-sync-command configs
Added remote configuration settings annex-ignore-command and annex-sync-command, which are dynamic equivilants of the annex-ignore and annex-sync configurations. For this I needed a new DynamicConfig infrastructure. Its implementation should be as fast as before when there is no dynamic config, and it caches so shell commands are only run once. Note that annex-ignore-command exits nonzero when the remote should be ignored. While that may seem backwards, it allows using the same command for it as for annex-sync-command when you want to disable both. This commit was sponsored by Trenton Cronholm on Patreon.
Diffstat (limited to 'Command')
-rw-r--r--Command/EnableRemote.hs9
-rw-r--r--Command/InitRemote.hs4
-rw-r--r--Command/Sync.hs17
3 files changed, 20 insertions, 10 deletions
diff --git a/Command/EnableRemote.hs b/Command/EnableRemote.hs
index b9b53a69c..a2a26009e 100644
--- a/Command/EnableRemote.hs
+++ b/Command/EnableRemote.hs
@@ -20,6 +20,8 @@ import qualified Remote.Git
import Logs.UUID
import Annex.UUID
import Config
+import Config.DynamicConfig
+import Types.GitConfig
import qualified Data.Map as M
@@ -76,7 +78,9 @@ startSpecialRemote name config (Just (u, c)) = do
let fullconfig = config `M.union` c
t <- either giveup return (Annex.SpecialRemote.findType fullconfig)
showStart "enableremote" name
- gc <- maybe def Remote.gitconfig <$> Remote.byUUID u
+ gc <- maybe (liftIO dummyRemoteGitConfig)
+ (return . Remote.gitconfig)
+ =<< Remote.byUUID u
next $ performSpecialRemote t u fullconfig gc
performSpecialRemote :: RemoteType -> UUID -> R.RemoteConfig -> RemoteGitConfig -> CommandPerform
@@ -109,5 +113,6 @@ unknownNameError prefix = do
where
isdisabled r = anyM id
[ (==) NoUUID <$> getRepoUUID r
- , remoteAnnexIgnore <$> Annex.getRemoteGitConfig r
+ , liftIO . getDynamicConfig . remoteAnnexIgnore
+ =<< Annex.getRemoteGitConfig r
]
diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs
index 78a1738d5..d82dc366c 100644
--- a/Command/InitRemote.hs
+++ b/Command/InitRemote.hs
@@ -15,6 +15,7 @@ import qualified Remote
import qualified Logs.Remote
import qualified Types.Remote as R
import Logs.UUID
+import Types.GitConfig
cmd :: Command
cmd = command "initremote" SectionSetup
@@ -46,7 +47,8 @@ start (name:ws) = ifM (isJust <$> findExisting name)
perform :: RemoteType -> String -> R.RemoteConfig -> CommandPerform
perform t name c = do
- (c', u) <- R.setup t R.Init cu Nothing c def
+ dummycfg <- liftIO dummyRemoteGitConfig
+ (c', u) <- R.setup t R.Init cu Nothing c dummycfg
next $ cleanup u name c'
where
cu = case M.lookup "uuid" c of
diff --git a/Command/Sync.hs b/Command/Sync.hs
index 9ecb98620..d460679ba 100644
--- a/Command/Sync.hs
+++ b/Command/Sync.hs
@@ -40,6 +40,7 @@ import qualified Git
import qualified Remote.Git
import Config
import Config.GitConfig
+import Config.DynamicConfig
import Config.Files
import Annex.Wanted
import Annex.Content
@@ -152,8 +153,8 @@ seek o = allowConcurrentOutput $ do
remotes <- syncRemotes (syncWith o)
let gitremotes = filter Remote.gitSyncableRemote remotes
- let dataremotes = filter (\r -> Remote.uuid r /= NoUUID) $
- filter (not . remoteAnnexIgnore . Remote.gitconfig) remotes
+ dataremotes <- filter (\r -> Remote.uuid r /= NoUUID)
+ <$> filterM (not <$$> liftIO . getDynamicConfig . remoteAnnexIgnore . Remote.gitconfig) remotes
-- Syncing involves many actions, any of which can independently
-- fail, without preventing the others from running.
@@ -247,10 +248,15 @@ remoteBranch remote = Git.Ref.underBase $ "refs/remotes/" ++ Remote.name remote
-- Do automatic initialization of remotes when possible when getting remote
-- list.
syncRemotes :: [String] -> Annex [Remote]
-syncRemotes ps = syncRemotes' ps =<< Remote.remoteList' True
+syncRemotes ps = do
+ remotelist <- Remote.remoteList' True
+ available <- filterM (liftIO . getDynamicConfig . remoteAnnexSync . Remote.gitconfig)
+ (filter (not . Remote.isXMPPRemote) remotelist)
+ syncRemotes' ps available
syncRemotes' :: [String] -> [Remote] -> Annex [Remote]
-syncRemotes' ps remotelist = ifM (Annex.getState Annex.fast) ( nub <$> pickfast , wanted )
+syncRemotes' ps available =
+ ifM (Annex.getState Annex.fast) ( nub <$> pickfast , wanted )
where
pickfast = (++) <$> listed <*> (filterM good (fastest available))
@@ -260,9 +266,6 @@ syncRemotes' ps remotelist = ifM (Annex.getState Annex.fast) ( nub <$> pickfast
listed = concat <$> mapM Remote.byNameOrGroup ps
- available = filter (remoteAnnexSync . Remote.gitconfig)
- $ filter (not . Remote.isXMPPRemote) remotelist
-
good r
| Remote.gitSyncableRemote r = Remote.Git.repoAvail $ Remote.repo r
| otherwise = return True