From 2607479890ac2b2a1bd63aca10dd87c9199bf414 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 3 Oct 2013 14:02:34 -0400 Subject: 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. --- Annex/Branch.hs | 13 +++++++++---- Locations.hs | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Annex/Branch.hs b/Annex/Branch.hs index b8c9d02e4..9dfdaa876 100644 --- a/Annex/Branch.hs +++ b/Annex/Branch.hs @@ -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. diff --git a/Locations.hs b/Locations.hs index b05cdc076..2e9fd574a 100644 --- a/Locations.hs +++ b/Locations.hs @@ -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" -- cgit v1.2.3