summaryrefslogtreecommitdiff
path: root/Upgrade/V1.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-11-08 15:34:10 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-11-08 16:27:20 -0400
commitbf460a0a98d7e4c7f4eac525fcf300629db582b6 (patch)
treebff7cd09529c40fa8cb76fd92428cc41e24ad808 /Upgrade/V1.hs
parent2ff8915365099501382183af9855e739fc234861 (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/V1.hs')
-rw-r--r--Upgrade/V1.hs28
1 files changed, 12 insertions, 16 deletions
diff --git a/Upgrade/V1.hs b/Upgrade/V1.hs
index be9a977ad..fe59ad3da 100644
--- a/Upgrade/V1.hs
+++ b/Upgrade/V1.hs
@@ -50,9 +50,9 @@ import qualified Upgrade.V2
upgrade :: Annex Bool
upgrade = do
showAction "v1 to v2"
-
- g <- gitRepo
- if Git.repoIsLocalBare g
+
+ bare <- fromRepo $ Git.repoIsLocalBare
+ if bare
then do
moveContent
setVersion
@@ -83,8 +83,8 @@ moveContent = do
updateSymlinks :: Annex ()
updateSymlinks = do
showAction "updating symlinks"
- g <- gitRepo
- files <- liftIO $ LsFiles.inRepo g [Git.workTree g]
+ top <- fromRepo Git.workTree
+ files <- inRepo $ LsFiles.inRepo [top]
forM_ files fixlink
where
fixlink f = do
@@ -104,8 +104,7 @@ moveLocationLogs = do
forM_ logkeys move
where
oldlocationlogs = do
- g <- gitRepo
- let dir = Upgrade.V2.gitStateDir g
+ dir <- fromRepo Upgrade.V2.gitStateDir
exists <- liftIO $ doesDirectoryExist dir
if exists
then do
@@ -113,9 +112,8 @@ moveLocationLogs = do
return $ mapMaybe oldlog2key contents
else return []
move (l, k) = do
- g <- gitRepo
- let dest = logFile2 g k
- let dir = Upgrade.V2.gitStateDir g
+ dest <- fromRepo $ logFile2 k
+ dir <- fromRepo $ Upgrade.V2.gitStateDir
let f = dir </> l
liftIO $ createDirectoryIfMissing True (parentDir dest)
-- could just git mv, but this way deals with
@@ -206,9 +204,7 @@ lookupFile1 file = do
" (unknown backend " ++ bname ++ ")"
getKeyFilesPresent1 :: Annex [FilePath]
-getKeyFilesPresent1 = do
- g <- gitRepo
- getKeyFilesPresent1' $ gitAnnexObjectDir g
+getKeyFilesPresent1 = getKeyFilesPresent1' =<< fromRepo gitAnnexObjectDir
getKeyFilesPresent1' :: FilePath -> Annex [FilePath]
getKeyFilesPresent1' dir = do
exists <- liftIO $ doesDirectoryExist dir
@@ -228,11 +224,11 @@ getKeyFilesPresent1' dir = do
logFile1 :: Git.Repo -> Key -> String
logFile1 repo key = Upgrade.V2.gitStateDir repo ++ keyFile1 key ++ ".log"
-logFile2 :: Git.Repo -> Key -> String
+logFile2 :: Key -> Git.Repo -> String
logFile2 = logFile' hashDirLower
-logFile' :: (Key -> FilePath) -> Git.Repo -> Key -> String
-logFile' hasher repo key =
+logFile' :: (Key -> FilePath) -> Key -> Git.Repo -> String
+logFile' hasher key repo =
gitStateDir repo ++ hasher key ++ keyFile key ++ ".log"
stateDir :: FilePath