aboutsummaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-08-24 20:50:39 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-08-24 20:50:39 -0400
commitc9b3b8829dc3f106583fb933808179ec02773790 (patch)
treed2b27b5d8ee40c74be33c83807761c5eb5cea584 /Annex
parent8de7699f3905f5a3feb88cd6297f982f3666a201 (diff)
thread safe git-annex index file use
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Branch.hs34
1 files changed, 20 insertions, 14 deletions
diff --git a/Annex/Branch.hs b/Annex/Branch.hs
index a832efada..f36f1c57b 100644
--- a/Annex/Branch.hs
+++ b/Annex/Branch.hs
@@ -25,7 +25,6 @@ module Annex.Branch (
import qualified Data.ByteString.Lazy.Char8 as L
import Common.Annex
-import Annex.Exception
import Annex.BranchState
import Annex.Journal
import qualified Git
@@ -37,9 +36,9 @@ import qualified Git.UpdateIndex
import Git.HashObject
import Git.Types
import Git.FilePath
-import qualified Git.Index
import Annex.CatFile
import Annex.Perms
+import qualified Annex
{- Name of the branch that is used to store git-annex's information. -}
name :: Git.Ref
@@ -280,12 +279,18 @@ withIndex = withIndex' False
withIndex' :: Bool -> Annex a -> Annex a
withIndex' bootstrapping a = do
f <- fromRepo gitAnnexIndex
- bracketIO (Git.Index.override f) id $ do
- checkIndexOnce $ unlessM (liftIO $ doesFileExist f) $ do
- unless bootstrapping create
- liftIO $ createDirectoryIfMissing True $ takeDirectory f
- unless bootstrapping $ inRepo genIndex
- a
+ g <- gitRepo
+ let g' = g { gitEnv = Just [("GIT_INDEX_FILE", f)] }
+
+ Annex.changeState $ \s -> s { Annex.repo = g' }
+ checkIndexOnce $ unlessM (liftIO $ doesFileExist f) $ do
+ unless bootstrapping create
+ liftIO $ createDirectoryIfMissing True $ takeDirectory f
+ unless bootstrapping $ inRepo genIndex
+ r <- a
+ Annex.changeState $ \s -> s { Annex.repo = (Annex.repo s) { gitEnv = gitEnv g} }
+
+ return r
{- Runs an action using the branch's index file, first making sure that
- the branch and index are up-to-date. -}
@@ -338,12 +343,13 @@ stageJournal :: Annex ()
stageJournal = do
showStoringStateAction
fs <- getJournalFiles
- g <- gitRepo
- withIndex $ liftIO $ do
- h <- hashObjectStart g
- Git.UpdateIndex.streamUpdateIndex g
- [genstream (gitAnnexJournalDir g) h fs]
- hashObjectStop h
+ withIndex $ do
+ g <- gitRepo
+ liftIO $ do
+ h <- hashObjectStart g
+ Git.UpdateIndex.streamUpdateIndex g
+ [genstream (gitAnnexJournalDir g) h fs]
+ hashObjectStop h
where
genstream dir h fs streamer = forM_ fs $ \file -> do
let path = dir </> file