2011-03-30 18:00:54 +00:00
|
|
|
{- common functions for special remotes
|
|
|
|
-
|
|
|
|
- Copyright 2011 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2011-08-17 00:49:54 +00:00
|
|
|
module Remote.Helper.Special where
|
2011-03-30 18:00:54 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as M
|
|
|
|
import Data.Maybe
|
|
|
|
import Data.String.Utils
|
|
|
|
import Control.Monad.State (liftIO)
|
|
|
|
|
|
|
|
import Types
|
2011-06-02 01:56:04 +00:00
|
|
|
import Types.Remote
|
2011-06-30 17:16:57 +00:00
|
|
|
import qualified Git
|
2011-03-30 18:00:54 +00:00
|
|
|
import qualified Annex
|
|
|
|
import UUID
|
2011-08-22 20:14:12 +00:00
|
|
|
import Utility.SafeCommand
|
2011-03-30 18:00:54 +00:00
|
|
|
|
|
|
|
{- Special remotes don't have a configured url, so Git.Repo does not
|
|
|
|
- automatically generate remotes for them. This looks for a different
|
|
|
|
- configuration key instead.
|
|
|
|
-}
|
|
|
|
findSpecialRemotes :: String -> Annex [Git.Repo]
|
|
|
|
findSpecialRemotes s = do
|
|
|
|
g <- Annex.gitRepo
|
|
|
|
return $ map construct $ remotepairs g
|
|
|
|
where
|
|
|
|
remotepairs r = M.toList $ M.filterWithKey match $ Git.configMap r
|
|
|
|
construct (k,_) = Git.repoRemoteNameSet Git.repoFromUnknown k
|
|
|
|
match k _ = startswith "remote." k && endswith (".annex-"++s) k
|
|
|
|
|
|
|
|
{- Sets up configuration for a special remote in .git/config. -}
|
2011-04-15 19:09:36 +00:00
|
|
|
gitConfigSpecialRemote :: UUID -> RemoteConfig -> String -> String -> Annex ()
|
2011-03-30 18:32:08 +00:00
|
|
|
gitConfigSpecialRemote u c k v = do
|
2011-03-30 18:00:54 +00:00
|
|
|
g <- Annex.gitRepo
|
|
|
|
liftIO $ do
|
2011-03-30 18:32:08 +00:00
|
|
|
Git.run g "config" [Param (configsetting $ "annex-"++k), Param v]
|
2011-07-15 16:47:14 +00:00
|
|
|
Git.run g "config" [Param (configsetting "annex-uuid"), Param u]
|
2011-03-30 18:00:54 +00:00
|
|
|
where
|
|
|
|
remotename = fromJust (M.lookup "name" c)
|
2011-03-30 18:32:08 +00:00
|
|
|
configsetting s = "remote." ++ remotename ++ "." ++ s
|