lockJournal when running performTransitions

This may not strictly be needed -- the transition code bypasses the
journal. However, this ensures that the git-annex branch is only
committed with the journal locked. This will allow for further
improvements.
This commit is contained in:
Joey Hess 2013-10-03 14:02:34 -04:00
parent be0b7341b4
commit 7a9a16b337
2 changed files with 11 additions and 5 deletions

View file

@ -404,7 +404,8 @@ stageJournal = withIndex $ do
- remote refs cannot be merged into the branch (since transitions
- throw away history), so they are added to the list of refs to ignore,
- to avoid re-merging content from them again.
-}
-
- Should be called only inside lockJournal. -}
handleTransitions :: Transitions -> [Git.Ref] -> Annex Bool
handleTransitions localts refs = do
m <- M.fromList <$> mapM getreftransition refs
@ -415,7 +416,7 @@ handleTransitions localts refs = do
let allts = combineTransitions (localts:remotets)
let (transitionedrefs, untransitionedrefs) =
partition (\r -> M.lookup r m == Just allts) refs
performTransitions allts (localts /= allts) transitionedrefs
performTransitionsLocked allts (localts /= allts) transitionedrefs
ignoreRefs untransitionedrefs
return True
where
@ -440,9 +441,13 @@ getIgnoredRefs = S.fromList . mapMaybe Git.Sha.extractSha . lines <$> content
liftIO $ catchDefaultIO "" $ readFile f
{- Performs the specified transitions on the contents of the index file,
- commits it to the branch, or creates a new branch. -}
- commits it to the branch, or creates a new branch.
-}
performTransitions :: Transitions -> Bool -> [Ref] -> Annex ()
performTransitions ts neednewlocalbranch transitionedrefs = do
performTransitions ts neednewlocalbranch transitionedrefs = lockJournal $
performTransitionsLocked ts neednewlocalbranch transitionedrefs
performTransitionsLocked :: Transitions -> Bool -> [Ref] -> Annex ()
performTransitionsLocked ts neednewlocalbranch transitionedrefs = do
-- For simplicity & speed, we're going to use the Annex.Queue to
-- update the git-annex branch, while it usually holds changes
-- for the head branch. Flush any such changes.

View file

@ -223,7 +223,8 @@ gitAnnexJournalLock r = gitAnnexDir r </> "journal.lck"
gitAnnexIndex :: Git.Repo -> FilePath
gitAnnexIndex r = gitAnnexDir r </> "index"
{- Lock file for .git/annex/index. -}
{- Lock file for .git/annex/index. Not to be confused with git's
- index.lock. -}
gitAnnexIndexLock :: Git.Repo -> FilePath
gitAnnexIndexLock r = gitAnnexDir r </> "index.lck"