summaryrefslogtreecommitdiff
path: root/Upgrade
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
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')
-rw-r--r--Upgrade/V0.hs3
-rw-r--r--Upgrade/V1.hs28
-rw-r--r--Upgrade/V2.hs40
3 files changed, 33 insertions, 38 deletions
diff --git a/Upgrade/V0.hs b/Upgrade/V0.hs
index b1443fa46..eae5c87ce 100644
--- a/Upgrade/V0.hs
+++ b/Upgrade/V0.hs
@@ -16,10 +16,9 @@ import qualified Upgrade.V1
upgrade :: Annex Bool
upgrade = do
showAction "v0 to v1"
- g <- gitRepo
-- do the reorganisation of the key files
- let olddir = gitAnnexDir g
+ olddir <- fromRepo gitAnnexDir
keys <- getKeysPresent0 olddir
forM_ keys $ \k -> moveAnnex k $ olddir </> keyFile0 k
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
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"