summaryrefslogtreecommitdiff
path: root/Command/InitRemote.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-03-29 13:49:54 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-03-29 14:10:12 -0400
commit05751d55cd8002e6a2a2afc520622fb6697472e3 (patch)
tree6a86d2ebfd6888f611d86ec33984ab512d28e087 /Command/InitRemote.hs
parenta3b6586902d6689b07c050b1fc50e19f4115c42e (diff)
clean up remote.log handling
Diffstat (limited to 'Command/InitRemote.hs')
-rw-r--r--Command/InitRemote.hs20
1 files changed, 17 insertions, 3 deletions
diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs
index cf6a341c5..0d9a40cd3 100644
--- a/Command/InitRemote.hs
+++ b/Command/InitRemote.hs
@@ -29,12 +29,12 @@ start :: CommandStartString
start params = notBareRepo $ do
when (null ws) $ error "Specify a name for the remote"
showStart "initremote" name
- r <- Remote.configGet name
- (u, c) <- case r of
+ m <- Remote.readRemoteLog
+ (u, c) <- case findByName name m of
Just t -> return t
Nothing -> do
uuid <- liftIO $ genUUID
- return $ (uuid, M.empty)
+ return $ (uuid, M.insert nameKey name M.empty)
return $ Just $ perform name u $ M.union config c
where
@@ -46,3 +46,17 @@ perform :: String -> UUID -> M.Map String String -> CommandPerform
perform name uuid config = do
liftIO $ putStrLn $ show $ (uuid, config)
return Nothing
+
+findByName :: String -> M.Map UUID (M.Map String String) -> Maybe (UUID, M.Map String String)
+findByName n m = if null matches then Nothing else Just $ head matches
+ where
+ matches = filter (matching . snd) $ M.toList m
+ matching c = case M.lookup nameKey c of
+ Nothing -> False
+ Just n'
+ | n' == n -> True
+ | otherwise -> False
+
+{- The name of a configured remote is stored in its config using this key. -}
+nameKey :: String
+nameKey = "name"