avoid unnecessary auto-merge when only changing a file in the branch.

Avoids doing auto-merging in commands that don't need fully current
information from the git-annex branch. In particular, git annex add no
longer needs to auto-merge. Affected commands: Anything that doesn't
look up data from the branch, but does write a change to it.

It might seem counterintuitive that we can change a value without first
making sure we have the current value. This optimisation works because
these two sequences are equivilant:

1. pull from remote
2. union merge
3. read file from branch
4. modify file and write to branch

vs.

1. read file from branch
2. modify file and write to branch
3. pull from remote
4. union merge

After either sequence, the git-annex branch contains the same logical content
for the modified file. (Possibly with lines in a different order or
additional old lines of course).
This commit is contained in:
Joey Hess 2011-11-12 15:15:57 -04:00
parent 897bf938f6
commit e9bfa8eaed
3 changed files with 25 additions and 5 deletions

View file

@ -244,9 +244,13 @@ siblingBranches = do
pair l = (head l, last l) pair l = (head l, last l)
uref (a, _) (b, _) = a == b uref (a, _) (b, _) = a == b
{- Applies a function to modifiy the content of a file. -} {- Applies a function to modifiy the content of a file.
-
- Note that this does not cause the branch to be merged, it only
- modifes the current content of the file on the branch.
-}
change :: FilePath -> (String -> String) -> Annex () change :: FilePath -> (String -> String) -> Annex ()
change file a = lockJournal $ get file >>= return . a >>= set file change file a = lockJournal $ getStale file >>= return . a >>= set file
{- Records new content of a file into the journal. -} {- Records new content of a file into the journal. -}
set :: FilePath -> String -> Annex () set :: FilePath -> String -> Annex ()
@ -259,13 +263,24 @@ set file content = do
- -
- Returns an empty string if the file doesn't exist yet. -} - Returns an empty string if the file doesn't exist yet. -}
get :: FilePath -> Annex String get :: FilePath -> Annex String
get file = fromcache =<< getCache file get = get' False
{- 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.) -}
getStale :: FilePath -> Annex String
getStale = get' True
get' :: Bool -> FilePath -> Annex String
get' staleok file = fromcache =<< getCache file
where where
fromcache (Just content) = return content fromcache (Just content) = return content
fromcache Nothing = fromjournal =<< getJournalFile file fromcache Nothing = fromjournal =<< getJournalFile file
fromjournal (Just content) = cache content fromjournal (Just content) = cache content
fromjournal Nothing = withIndexUpdate $ fromjournal Nothing
cache =<< catFile fullname file | staleok = withIndex frombranch
| otherwise = withIndexUpdate $ frombranch >>= cache
frombranch = catFile fullname file
cache content = do cache content = do
setCache file content setCache file content
return content return content

3
debian/changelog vendored
View file

@ -1,6 +1,9 @@
git-annex (3.20111112) UNRELEASED; urgency=low git-annex (3.20111112) UNRELEASED; urgency=low
* merge: Improve commit messages to mention what was merged. * merge: Improve commit messages to mention what was merged.
* Avoid doing auto-merging in commands that don't need fully current
information from the git-annex branch. In particular, git annex add
no longer needs to auto-merge.
-- Joey Hess <joeyh@debian.org> Sat, 12 Nov 2011 14:50:21 -0400 -- Joey Hess <joeyh@debian.org> Sat, 12 Nov 2011 14:50:21 -0400

View file

@ -16,3 +16,5 @@ occurs before it has done anything, so ctrl-c should not be a problem
there. there.
This is a delicate change, I need to take care.. --[[Joey]] This is a delicate change, I need to take care.. --[[Joey]]
> [[done]] (assuming I didn't miss any cases where this is not safe!) --[[Joey]]