more monadic operator use

This commit is contained in:
Joey Hess 2011-05-15 15:27:49 -04:00
parent 1e5beda86a
commit 6aab88fa25
5 changed files with 11 additions and 20 deletions

View file

@ -86,9 +86,7 @@ getState c = liftM c get
- Example: changeState (\s -> s { quiet = True }) - Example: changeState (\s -> s { quiet = True })
-} -}
changeState :: (AnnexState -> AnnexState) -> Annex () changeState :: (AnnexState -> AnnexState) -> Annex ()
changeState a = do changeState a = put . a =<< get
state <- get
put (a state)
{- Returns the git repository being acted on -} {- Returns the git repository being acted on -}
gitRepo :: Annex Git.Repo gitRepo :: Annex Git.Repo

View file

@ -72,8 +72,7 @@ calcGitLink file key = do
- updated instead. -} - updated instead. -}
logStatus :: Key -> LogStatus -> Annex () logStatus :: Key -> LogStatus -> Annex ()
logStatus key status = do logStatus key status = do
g <- Annex.gitRepo u <- getUUID =<< Annex.gitRepo
u <- getUUID g
logStatusFor u key status logStatusFor u key status
{- Updates the LocationLog when a key's presence changes in a repository {- Updates the LocationLog when a key's presence changes in a repository

View file

@ -150,16 +150,13 @@ mapLog m l =
then Map.insert u l m then Map.insert u l m
else m else m
where where
better = case Map.lookup u m of better = maybe True (\l' -> date l' <= date l) $ Map.lookup u m
Just l' -> (date l' <= date l)
Nothing -> True
u = uuid l u = uuid l
{- Finds all keys that have location log information. {- Finds all keys that have location log information.
- (There may be duplicate keys in the list.) -} - (There may be duplicate keys in the list.) -}
loggedKeys :: Git.Repo -> IO [Key] loggedKeys :: Git.Repo -> IO [Key]
loggedKeys repo = do loggedKeys repo = do
let dir = gitStateDir repo
exists <- doesDirectoryExist dir exists <- doesDirectoryExist dir
if exists if exists
then do then do
@ -172,3 +169,4 @@ loggedKeys repo = do
else return [] else return []
where where
tryDirContents d = catch (dirContents d) (return . const []) tryDirContents d = catch (dirContents d) (return . const [])
dir = gitStateDir repo

View file

@ -75,10 +75,10 @@ genList = do
return rs' return rs'
else return rs else return rs
where where
process m t = do process m t =
l <- enumerate t enumerate t >>=
l' <- filterM remoteNotIgnored l filterM remoteNotIgnored >>=
mapM (gen m t) l' mapM (gen m t)
gen m t r = do gen m t r = do
u <- getUUID r u <- getUUID r
generate t r u (M.lookup u m) generate t r u (M.lookup u m)
@ -97,9 +97,7 @@ byName n = do
{- Looks up a remote by name (or by UUID), and returns its UUID. -} {- Looks up a remote by name (or by UUID), and returns its UUID. -}
nameToUUID :: String -> Annex UUID nameToUUID :: String -> Annex UUID
nameToUUID "." = do -- special case for current repo nameToUUID "." = getUUID =<< Annex.gitRepo -- special case for current repo
g <- Annex.gitRepo
getUUID g
nameToUUID n = liftM uuid (byName n) nameToUUID n = liftM uuid (byName n)
{- Cost ordered lists of remotes that the LocationLog indicate may have a key. {- Cost ordered lists of remotes that the LocationLog indicate may have a key.

View file

@ -79,8 +79,7 @@ getUncachedUUID r = Git.configGet r configkey ""
{- Make sure that the repo has an annex.uuid setting. -} {- Make sure that the repo has an annex.uuid setting. -}
prepUUID :: Annex () prepUUID :: Annex ()
prepUUID = do prepUUID = do
g <- Annex.gitRepo u <- getUUID =<< Annex.gitRepo
u <- getUUID g
when ("" == u) $ do when ("" == u) $ do
uuid <- liftIO $ genUUID uuid <- liftIO $ genUUID
setConfig configkey uuid setConfig configkey uuid
@ -88,8 +87,7 @@ prepUUID = do
{- Pretty-prints a list of UUIDs -} {- Pretty-prints a list of UUIDs -}
prettyPrintUUIDs :: [UUID] -> Annex String prettyPrintUUIDs :: [UUID] -> Annex String
prettyPrintUUIDs uuids = do prettyPrintUUIDs uuids = do
g <- Annex.gitRepo here <- getUUID =<< Annex.gitRepo
here <- getUUID g
m <- uuidMap m <- uuidMap
return $ unwords $ map (\u -> "\t" ++ prettify m u here ++ "\n") uuids return $ unwords $ map (\u -> "\t" ++ prettify m u here ++ "\n") uuids
where where