From 102e182eac9b95e31fb71830fe5ce5a502e93d92 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 12 Apr 2014 15:59:34 -0400 Subject: sync, assistant, remotedaemon: Use ssh connection caching for git pushes and pulls. For sync, saves 1 ssh connection per remote. For remotedaemon, the same ssh connection that is already open to run git-annex-shell notifychanges is reused to pull from the remote. Only potential problem is that this also enables connection caching when the assistant syncs with a ssh remote. Including the sync it does when a network connection has just come up. In that case, cached ssh connections are likely to be stale, and so using them would hang. Until I'm sure such problems have been dealt with, this commit needs to stay on the remotecontrol branch, and not be merged to master. This commit was sponsored by Alexandre Dupas. --- Command/Sync.hs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'Command/Sync.hs') diff --git a/Command/Sync.hs b/Command/Sync.hs index a4004736a..dfcb0d22a 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -21,7 +21,6 @@ import qualified Git.LsFiles as LsFiles import qualified Git.Branch import qualified Git.Ref import qualified Git -import qualified Types.Remote import qualified Remote.Git import Config import Annex.Wanted @@ -32,6 +31,7 @@ import Logs.Location import Annex.Drop import Annex.UUID import Annex.AutoMerge +import Annex.Ssh import Control.Concurrent.MVar @@ -113,11 +113,11 @@ syncRemotes rs = ifM (Annex.getState Annex.fast) ( nub <$> pickfast , wanted ) | null rs = filterM good =<< concat . Remote.byCost <$> available | otherwise = listed listed = catMaybes <$> mapM (Remote.byName . Just) rs - available = filter (remoteAnnexSync . Types.Remote.gitconfig) + available = filter (remoteAnnexSync . Remote.gitconfig) . filter (not . Remote.isXMPPRemote) <$> Remote.remoteList good r - | Remote.gitSyncableRemote r = Remote.Git.repoAvail $ Types.Remote.repo r + | Remote.gitSyncableRemote r = Remote.Git.repoAvail $ Remote.repo r | otherwise = return True fastest = fromMaybe [] . headMaybe . Remote.byCost @@ -201,7 +201,7 @@ pullRemote remote branch = do stopUnless fetch $ next $ mergeRemote remote branch where - fetch = inRepo $ Git.Command.runBool + fetch = inRepoWithSshCachingTo (Remote.repo remote) $ Git.Command.runBool [Param "fetch", Param $ Remote.name remote] {- The remote probably has both a master and a synced/master branch. @@ -227,14 +227,15 @@ pushRemote _remote Nothing = stop pushRemote remote (Just branch) = go =<< needpush where needpush - | remoteAnnexReadOnly (Types.Remote.gitconfig remote) = return False + | remoteAnnexReadOnly (Remote.gitconfig remote) = return False | otherwise = anyM (newer remote) [syncBranch branch, Annex.Branch.name] go False = stop go True = do showStart "push" (Remote.name remote) next $ next $ do showOutput - ok <- inRepo $ pushBranch remote branch + ok <- inRepoWithSshCachingTo (Remote.repo remote) $ + pushBranch remote branch unless ok $ do warning $ unwords [ "Pushing to " ++ Remote.name remote ++ " failed." ] showLongNote "(non-fast-forward problems can be solved by setting receive.denyNonFastforwards to false in the remote's git config)" @@ -367,7 +368,7 @@ syncFile rs f (k, _) = do next $ next $ getViaTmp k $ \dest -> getKeyFile' k (Just f) dest have wantput r - | Remote.readonly r || remoteAnnexReadOnly (Types.Remote.gitconfig r) = return False + | Remote.readonly r || remoteAnnexReadOnly (Remote.gitconfig r) = return False | otherwise = wantSend True (Just k) (Just f) (Remote.uuid r) handleput lack = ifM (inAnnex k) ( map put <$> filterM wantput lack -- cgit v1.2.3