diff options
author | Joey Hess <joey@kitenet.net> | 2011-11-08 15:34:10 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-11-08 16:27:20 -0400 |
commit | bf460a0a98d7e4c7f4eac525fcf300629db582b6 (patch) | |
tree | bff7cd09529c40fa8cb76fd92428cc41e24ad808 /Upgrade/V2.hs | |
parent | 2ff8915365099501382183af9855e739fc234861 (diff) |
reorder repo parameters last
Many functions took the repo as their first parameter. Changing it
consistently to be the last parameter allows doing some useful things with
currying, that reduce boilerplate.
In particular, g <- gitRepo is almost never needed now, instead
use inRepo to run an IO action in the repo, and fromRepo to get
a value from the repo.
This also provides more opportunities to use monadic and applicative
combinators.
Diffstat (limited to 'Upgrade/V2.hs')
-rw-r--r-- | Upgrade/V2.hs | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/Upgrade/V2.hs b/Upgrade/V2.hs index 67f0205c1..7ef2a4d18 100644 --- a/Upgrade/V2.hs +++ b/Upgrade/V2.hs @@ -37,45 +37,46 @@ olddir g upgrade :: Annex Bool upgrade = do showAction "v2 to v3" - g <- gitRepo - let bare = Git.repoIsLocalBare g + bare <- fromRepo Git.repoIsLocalBare + old <- fromRepo olddir Annex.Branch.create showProgress - e <- liftIO $ doesDirectoryExist (olddir g) + e <- liftIO $ doesDirectoryExist old when e $ do - mapM_ (\(k, f) -> inject f $ logFile k) =<< locationLogs g - mapM_ (\f -> inject f f) =<< logFiles (olddir g) + mapM_ (\(k, f) -> inject f $ logFile k) =<< locationLogs + mapM_ (\f -> inject f f) =<< logFiles old saveState showProgress - when e $ liftIO $ do - Git.run g "rm" [Param "-r", Param "-f", Param "-q", File (olddir g)] - unless bare $ gitAttributesUnWrite g + when e $ do + inRepo $ Git.run "rm" [Param "-r", Param "-f", Param "-q", File old] + unless bare $ inRepo $ gitAttributesUnWrite showProgress unless bare push return True -locationLogs :: Git.Repo -> Annex [(Key, FilePath)] -locationLogs repo = liftIO $ do - levela <- dirContents dir - levelb <- mapM tryDirContents levela - files <- mapM tryDirContents (concat levelb) - return $ mapMaybe islogfile (concat files) +locationLogs :: Annex [(Key, FilePath)] +locationLogs = do + dir <- fromRepo gitStateDir + liftIO $ do + levela <- dirContents dir + levelb <- mapM tryDirContents levela + files <- mapM tryDirContents (concat levelb) + return $ mapMaybe islogfile (concat files) where tryDirContents d = catch (dirContents d) (return . const []) - dir = gitStateDir repo islogfile f = maybe Nothing (\k -> Just (k, f)) $ logFileKey $ takeFileName f inject :: FilePath -> FilePath -> Annex () inject source dest = do - g <- gitRepo - new <- liftIO (readFile $ olddir g </> source) + old <- fromRepo olddir + new <- liftIO (readFile $ old </> source) Annex.Branch.change dest $ \prev -> unlines $ nub $ lines prev ++ lines new @@ -102,8 +103,7 @@ push = do Annex.Branch.update -- just in case showAction "pushing new git-annex branch to origin" showOutput - g <- gitRepo - liftIO $ Git.run g "push" [Param "origin", Param Annex.Branch.name] + inRepo $ Git.run "push" [Param "origin", Param Annex.Branch.name] _ -> do -- no origin exists, so just let the user -- know about the new branch @@ -126,7 +126,7 @@ gitAttributesUnWrite repo = do c <- readFileStrict attributes liftIO $ viaTmp writeFile attributes $ unlines $ filter (`notElem` attrLines) $ lines c - Git.run repo "add" [File attributes] + Git.run "add" [File attributes] repo stateDir :: FilePath stateDir = addTrailingPathSeparator ".git-annex" |