summaryrefslogtreecommitdiff
path: root/Annex/Branch.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-05-20 15:14:59 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-05-20 15:14:59 -0400
commit55b266130ca7dbfdc6316edf61a525683ecaa937 (patch)
tree30f7239635281e010d312837e58c086e2d48bca2 /Annex/Branch.hs
parentdcd8970a8feae8b699922f5bd1d69d698f0b0c4f (diff)
Fix a bug in the git-annex branch handling code that could cause info from a remote to not be merged and take effect immediately.
This bug was turned up by the test suite, running fsck in direct mode. A repository was cloned, was put into direct mode, was fscked, and fsck incorrectly said that no copy existed of a file, that was actually present in origin. This turned out to occur because fsck first did a Annex.Branch.change, recording that it did not locally have the file. That was recorded in the journal. Since neither the git annex direct not the fsck had yet needed to read any info from the branch, but had only made changes to it, the origin/git-annex branch was not yet merged in. So the journal got a location log entry written to it, but this did not include the location log info for the origin. When fsck then did a Annex.Branch.get, it trusted the journal was cosnsitent, and returned it, again w/o merging from origin/git-annex. This latter behavior is the actual bug. Refer to commit e9bfa8eaed3ff59a4c0bc8d4d677bc493177807c for the thinking behind it being ok to make a change to a file on the branch, without first merging the branch. That thinking still stands. However, it means that files in the journal cannot be trusted to be consistent if the branch has not been merged. So, to fix, just enure the branch gets merged, even when reading from the journal. In tests, this does not seem to cause any extra merging. Except, of course, in the one case described above. But git annex add, etc, are able to make changes w/o first merging the branch.
Diffstat (limited to 'Annex/Branch.hs')
-rw-r--r--Annex/Branch.hs29
1 files changed, 13 insertions, 16 deletions
diff --git a/Annex/Branch.hs b/Annex/Branch.hs
index 2cba28901..6578471bc 100644
--- a/Annex/Branch.hs
+++ b/Annex/Branch.hs
@@ -151,33 +151,30 @@ updateTo pairs = do
(nub $ fullname:refs)
liftIO cleanjournal
-{- Gets the content of a file, which may be in the journal, or committed
- - to the branch. Due to limitatons of git cat-file, does *not* get content
- - that has only been staged to the index.
+{- Gets the content of a file, which may be in the journal, or in the index
+ - (and committed to the branch).
-
- Updates the branch if necessary, to ensure the most up-to-date available
- content is available.
-
- Returns an empty string if the file doesn't exist yet. -}
get :: FilePath -> Annex String
-get = get' False
+get file = do
+ update
+ get' file
{- Like get, but does not merge the branch, so the info returned may not
- - reflect changes in remotes. (Changing the value this returns, and then
- - merging is always the same as using get, and then changing its value.) -}
+ - reflect changes in remotes.
+ - (Changing the value this returns, and then merging is always the
+ - same as using get, and then changing its value.) -}
getStale :: FilePath -> Annex String
-getStale = get' True
+getStale = get'
-get' :: Bool -> FilePath -> Annex String
-get' staleok file = fromjournal =<< getJournalFile file
+get' :: FilePath -> Annex String
+get' file = go =<< getJournalFile file
where
- fromjournal (Just content) = return content
- fromjournal Nothing
- | staleok = withIndex frombranch
- | otherwise = do
- update
- frombranch
- frombranch = withIndex $ L.unpack <$> catFile fullname file
+ go (Just journalcontent) = return journalcontent
+ go Nothing = withIndex $ L.unpack <$> catFile fullname file
{- Applies a function to modifiy the content of a file.
-