From 6ef82665de86195a7da6cffcba40874eba06424f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 20 Jan 2012 17:13:36 -0400 Subject: [PATCH] add annex.sshcaching config setting --- Annex/Ssh.hs | 29 +++++++++++++++++++---------- doc/git-annex.mdwn | 4 ++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Annex/Ssh.hs b/Annex/Ssh.hs index cd832a373f..7f5ba48d84 100644 --- a/Annex/Ssh.hs +++ b/Annex/Ssh.hs @@ -15,28 +15,37 @@ import System.IO.Error (try) import Common.Annex import Annex.LockPool +import qualified Git +import qualified Git.Config {- Generates parameters to ssh to a given host (or user@host) on a given - port, with connection caching. -} sshParams :: (String, Maybe Integer) -> Annex [CommandParam] -sshParams (host, port) = do - cleanstale - (socketfile, params) <- sshInfo (host, port) - liftIO $ createDirectoryIfMissing True $ parentDir socketfile - lockFile $ socket2lock socketfile - return params +sshParams (host, port) = go =<< sshInfo (host, port) where + go (Nothing, params) = return params + go (Just socketfile, params) = do + cleanstale + liftIO $ createDirectoryIfMissing True $ parentDir socketfile + lockFile $ socket2lock socketfile + return params -- If the lock pool is empty, this is the first ssh of this -- run. There could be stale ssh connections hanging around -- from a previous git-annex run that was interrupted. cleanstale = whenM (null . filter isLock . M.keys <$> getPool) $ sshCleanup -sshInfo :: (String, Maybe Integer) -> Annex (FilePath, [CommandParam]) +sshInfo :: (String, Maybe Integer) -> Annex (Maybe FilePath, [CommandParam]) sshInfo (host, port) = do - dir <- fromRepo $ gitAnnexSshDir - let socketfile = dir hostport2socket host port - return $ (socketfile, cacheParams socketfile ++ portParams port ++ [Param host]) + caching <- Git.configTrue <$> fromRepo (Git.Config.get "annex.sshcaching" "true") + if caching + then do + dir <- fromRepo $ gitAnnexSshDir + let socketfile = dir hostport2socket host port + return $ (Just socketfile, cacheParams socketfile ++ params) + else return (Nothing, params) + where + params = portParams port ++ [Param host] cacheParams :: FilePath -> [CommandParam] cacheParams socketfile = diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index a377665c68..148b6336de 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -575,6 +575,10 @@ Here are all the supported configuration settings. Automatically maintained, and used to automate upgrades between versions. +* `annex.sshcaching` + + By default, git-annex caches ssh connections. To disable this, set to `false`. + * `remote..annex-cost` When determining which repository to