summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-06-23 15:51:07 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-06-23 16:05:02 -0400
commit7981eb4cb512fbe3c49a3dd165c31be14ae4bc49 (patch)
tree157497de52adaf40f7589f06e01c46607f36d158
parent780ee5ff6d3fdcbbe69450d40260c1083315ca47 (diff)
fix consistency, and partially close a race during merge
Only "partially" because the journal is not locked during the merge, so there's a small window where a different git-annex process could write info to the journal that overwrites info taken from the merge. That could be dealt with by locking, but the lock would really need to be around the whole git-annex, to only let one run at a time. Otherwise, even with the journal locked during the merge, another git-annex could already be running, generate an overwriting change, and only store it in the journal after the merge was complete. And similarly, two git-annex processes could fight and overwrite each other's information independant of any merging. So, a toplevel lock for git-annex may get added; it's something I've considered before, as these potential, unlikely problems are not new. (OTOH, fsck will deal with such problems.)
-rw-r--r--Branch.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/Branch.hs b/Branch.hs
index 10a790631..e79ca3f60 100644
--- a/Branch.hs
+++ b/Branch.hs
@@ -149,6 +149,21 @@ update :: Annex ()
update = do
state <- Annex.getState Annex.branchstate
unless (branchUpdated state) $ withIndex $ do
+ {- Since branches get merged into the index, it's important to
+ - first stage the journal into the index. Otherwise, any
+ - changes in the journal would later get staged, and might
+ - overwrite changes made during the merge.
+ -
+ - It would be cleaner to handle the merge by updating the
+ - journal, not the index, with changes from the branches.
+ -
+ - XXX Anything written to the journal during the merge,
+ - by another process could still race the merge. The
+ - journal should really be blocking locked during the
+ - merge.
+ -}
+ _ <- stageJournalFiles
+
g <- Annex.gitRepo
r <- liftIO $ Git.pipeRead g [Param "show-ref", Param name]
let refs = map (last . words) (lines r)