split out three modules from Git

Constructors and configuration make sense in separate modules.
A separate Git.Types is needed to avoid cycles.
This commit is contained in:
Joey Hess 2011-12-13 15:05:07 -04:00
parent 46588674b0
commit 13fff71f20
20 changed files with 349 additions and 285 deletions

View file

@ -9,6 +9,7 @@ module Config where
import Common.Annex
import qualified Git
import qualified Git.Config
import qualified Annex
type ConfigKey = String
@ -18,15 +19,15 @@ setConfig :: ConfigKey -> String -> Annex ()
setConfig k value = do
inRepo $ Git.run "config" [Param k, Param value]
-- re-read git config and update the repo's state
newg <- inRepo Git.configRead
newg <- inRepo Git.Config.read
Annex.changeState $ \s -> s { Annex.repo = newg }
{- Looks up a per-remote config setting in git config.
- Failing that, tries looking for a global config option. -}
getConfig :: Git.Repo -> ConfigKey -> String -> Annex String
getConfig r key def = do
def' <- fromRepo $ Git.configGet ("annex." ++ key) def
fromRepo $ Git.configGet (remoteConfig r key) def'
def' <- fromRepo $ Git.Config.get ("annex." ++ key) def
fromRepo $ Git.Config.get (remoteConfig r key) def'
{- Looks up a per-remote config setting in git config. -}
remoteConfig :: Git.Repo -> ConfigKey -> String
@ -83,6 +84,6 @@ getNumCopies v = perhaps (use v) =<< Annex.getState Annex.forcenumcopies
where
use (Just n) = return n
use Nothing = perhaps (return 1) =<<
readMaybe <$> fromRepo (Git.configGet config "1")
readMaybe <$> fromRepo (Git.Config.get config "1")
perhaps fallback = maybe fallback (return . id)
config = "annex.numcopies"