summaryrefslogtreecommitdiff
path: root/Command/Vicfg.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-10-03 19:37:39 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-10-03 19:37:39 -0400
commitd96bfd3b6dc95647b2ec86174a28ce4fbb597583 (patch)
tree931b5dce045c026da11f2c15f3314a664362bdb8 /Command/Vicfg.hs
parent00faeb400e42ec5e0fc32d1b9d6cce2281ccbccc (diff)
finished vicfg
One note: Deleted lines are not currently parsed as config changes. That makes sense for trust settings. It may make sense to support deleted lines as a way to clear group settings.
Diffstat (limited to 'Command/Vicfg.hs')
-rw-r--r--Command/Vicfg.hs19
1 files changed, 14 insertions, 5 deletions
diff --git a/Command/Vicfg.hs b/Command/Vicfg.hs
index 3170488e5..a7090e190 100644
--- a/Command/Vicfg.hs
+++ b/Command/Vicfg.hs
@@ -50,7 +50,7 @@ vicfg curcfg f = do
Left s -> do
liftIO $ writeFile f s
vicfg curcfg f
- Right c -> setCfg c
+ Right newcfg -> setCfg curcfg newcfg
data Cfg = Cfg
{ cfgTrustMap :: TrustMap
@@ -67,8 +67,17 @@ getCfg = Cfg
emptyCfg :: Cfg
emptyCfg = Cfg M.empty M.empty M.empty
-setCfg :: Cfg -> Annex ()
-setCfg = error "TODO setCfg"
+setCfg :: Cfg -> Cfg -> Annex ()
+setCfg curcfg newcfg = do
+ let (trustchanges, groupchanges) = diffCfg curcfg newcfg
+ mapM_ (\(u,t) -> trustSet u t) $ M.toList trustchanges
+ mapM_ (\(u, gs) -> groupChange u $ const gs) $ M.toList groupchanges
+
+diffCfg :: Cfg -> Cfg -> (TrustMap, M.Map UUID (S.Set Group))
+diffCfg curcfg newcfg = (diff cfgTrustMap, diff cfgGroupMap)
+ where
+ diff f = M.differenceWith (\x y -> if x == y then Nothing else Just x)
+ (f newcfg) (f curcfg)
genCfg :: Cfg -> String
genCfg cfg = unlines $ concat
@@ -98,8 +107,8 @@ genCfg cfg = unlines $ concat
, com "Repository groups"
, com "(Separate group names with spaces)"
]
- groups = map (\(s, u) -> line "group" u $ unwords $ S.toList s) $
- sort $ map swap $ M.toList $ cfgGroupMap cfg
+ groups = sort $ map (\(s, u) -> line "group" u $ unwords $ S.toList s) $
+ map swap $ M.toList $ cfgGroupMap cfg
defaultgroups = map (\u -> pcom $ line "group" u "") $
missing cfgGroupMap