diff options
author | Joey Hess <joey@kitenet.net> | 2011-05-15 02:49:43 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-05-15 03:38:08 -0400 |
commit | cad0e1c8b7eb21f8dceca8dd9fa3bc1d1aa7eabd (patch) | |
tree | b6be12dc1cc83a35ca7d89a862d85e6d71c38572 /Command | |
parent | efa7f544050c0d5be6bc1b0fc0125278e475c213 (diff) |
simplified a bunch of Maybe handling
Diffstat (limited to 'Command')
-rw-r--r-- | Command/DropUnused.hs | 9 | ||||
-rw-r--r-- | Command/InitRemote.hs | 17 | ||||
-rw-r--r-- | Command/Map.hs | 16 | ||||
-rw-r--r-- | Command/Unused.hs | 14 |
4 files changed, 24 insertions, 32 deletions
diff --git a/Command/DropUnused.hs b/Command/DropUnused.hs index 861c78c90..965a99ed5 100644 --- a/Command/DropUnused.hs +++ b/Command/DropUnused.hs @@ -58,14 +58,13 @@ start (unused, unusedbad, unusedtmp) s = notBareRepo $ search next $ a key perform :: Key -> CommandPerform -perform key = do - from <- Annex.getState Annex.fromremote - case from of - Just name -> do +perform key = maybe droplocal dropremote =<< Annex.getState Annex.fromremote + where + dropremote name = do r <- Remote.byName name showNote $ "from " ++ Remote.name r ++ "..." next $ Command.Move.fromCleanup r True key - _ -> do + droplocal = do backend <- keyBackend key Command.Drop.perform key backend (Just 0) -- force drop diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs index eda50ee5d..261ccdc8b 100644 --- a/Command/InitRemote.hs +++ b/Command/InitRemote.hs @@ -68,11 +68,11 @@ cleanup u c = do findByName :: String -> Annex (UUID, RemoteClass.RemoteConfig) findByName name = do m <- Remote.readRemoteLog - case findByName' name m of - Just i -> return i - Nothing -> do + maybe generate return $ findByName' name m + where + generate = do uuid <- liftIO $ genUUID - return $ (uuid, M.insert nameKey name M.empty) + return (uuid, M.insert nameKey name M.empty) findByName' :: String -> M.Map UUID RemoteClass.RemoteConfig -> Maybe (UUID, RemoteClass.RemoteConfig) findByName' n m = if null matches then Nothing else Just $ head matches @@ -86,12 +86,13 @@ findByName' n m = if null matches then Nothing else Just $ head matches {- find the specified remote type -} findType :: RemoteClass.RemoteConfig -> Annex (RemoteClass.RemoteType Annex) -findType config = - case M.lookup typeKey config of - Nothing -> error "Specify the type of remote with type=" - Just s -> case filter (\i -> RemoteClass.typename i == s) Remote.remoteTypes of +findType config = maybe unspecified specified $ M.lookup typeKey config + where + unspecified = error "Specify the type of remote with type=" + specified s = case filter (findtype s) Remote.remoteTypes of [] -> error $ "Unknown remote type " ++ s (t:_) -> return t + findtype s i = RemoteClass.typename i == s {- The name of a configured remote is stored in its config using this key. -} nameKey :: String diff --git a/Command/Map.hs b/Command/Map.hs index 3c94fc75b..7a9121b69 100644 --- a/Command/Map.hs +++ b/Command/Map.hs @@ -84,10 +84,7 @@ repoName umap r | otherwise = M.findWithDefault fallback repouuid umap where repouuid = getUncachedUUID r - fallback = - case (Git.repoRemoteName r) of - Just n -> n - Nothing -> "unknown" + fallback = maybe "unknown" id $ Git.repoRemoteName r {- A unique id for the node for a repo. Uses the annex.uuid if available. -} nodeId :: Git.Repo -> String @@ -121,13 +118,10 @@ edge umap fullinfo from to = {- Only name an edge if the name is different than the name - that will be used for the destination node, and is - different from its hostname. (This reduces visual clutter.) -} - edgename = - case (Git.repoRemoteName to) of - Nothing -> Nothing - Just n -> - if (n == repoName umap fullto || n == hostname fullto) - then Nothing - else Just n + edgename = maybe Nothing calcname $ Git.repoRemoteName to + calcname n + | n == repoName umap fullto || n == hostname fullto = Nothing + | otherwise = Just n unreachable :: String -> String unreachable = Dot.fillColor "red" diff --git a/Command/Unused.hs b/Command/Unused.hs index 7570dfe90..a2e1c86de 100644 --- a/Command/Unused.hs +++ b/Command/Unused.hs @@ -41,12 +41,7 @@ start = notBareRepo $ do perform :: CommandPerform perform = do - from <- Annex.getState Annex.fromremote - case from of - Just name -> do - r <- Remote.byName name - checkRemoteUnused r - _ -> checkUnused + maybe checkUnused checkRemoteUnused =<< Annex.getState Annex.fromremote next $ return True checkUnused :: Annex () @@ -63,8 +58,11 @@ checkUnused = do writeUnusedFile file unusedlist return $ length l -checkRemoteUnused :: Remote.Remote Annex -> Annex () -checkRemoteUnused r = do +checkRemoteUnused :: String -> Annex () +checkRemoteUnused name = checkRemoteUnused' =<< Remote.byName name + +checkRemoteUnused' :: Remote.Remote Annex -> Annex () +checkRemoteUnused' r = do g <- Annex.gitRepo showNote $ "checking for unused data on " ++ Remote.name r ++ "..." referenced <- getKeysReferenced |