avoid redundant call to updateIndex

commitBranch calls updateIndex
This commit is contained in:
Joey Hess 2011-12-11 21:40:36 -04:00
parent c4c965d602
commit 29b88ad657

View file

@ -203,38 +203,42 @@ commit message = whenM journalDirty $ lockJournal $ do
- (It would be cleaner to handle the merge by updating the journal, not the - (It would be cleaner to handle the merge by updating the journal, not the
- index, with changes from the branches.) - index, with changes from the branches.)
- -
- The index is always updated using a union merge, as that's the most - The branch is fast-forwarded if possible, otherwise a merge commit is
- efficient way to update it. However, if the branch can be - made.
- fast-forwarded, that is then done, rather than adding an unnecessary
- commit to it.
-} -}
update :: Annex () update :: Annex ()
update = onceonly $ do update = onceonly $ do
-- ensure branch exists, and index is up-to-date -- ensure branch exists
create create
_ <- updateIndex
-- check what needs updating before taking the lock -- check what needs updating before taking the lock
dirty <- journalDirty dirty <- journalDirty
c <- filterM (changedBranch name . snd) =<< siblingBranches c <- filterM (changedBranch name . snd) =<< siblingBranches
let (refs, branches) = unzip c let (refs, branches) = unzip c
unless (not dirty && null refs) $ withIndex $ lockJournal $ do if (not dirty && null refs)
when dirty stageJournalFiles then simpleupdate
let merge_desc = if null branches else withIndex $ lockJournal $ do
then "update" when dirty stageJournalFiles
else "merging " ++ let merge_desc = if null branches
unwords (map Git.refDescribe branches) ++ then "update"
" into " ++ show name else "merging " ++
unless (null branches) $ do unwords (map Git.refDescribe branches) ++
showSideAction merge_desc " into " ++ show name
mergeIndex branches unless (null branches) $ do
ff <- if dirty then return False else tryFastForwardTo refs showSideAction merge_desc
unless ff $ commitBranch merge_desc (nub $ fullname:refs) mergeIndex branches
invalidateCache ff <- if dirty then return False else tryFastForwardTo refs
if ff
then simpleupdate
else commitBranch merge_desc (nub $ fullname:refs)
invalidateCache
where where
onceonly a = unlessM (branchUpdated <$> getState) $ do onceonly a = unlessM (branchUpdated <$> getState) $ do
r <- a r <- a
disableUpdate disableUpdate
return r return r
simpleupdate = do
_ <- updateIndex
return ()
{- Checks if the second branch has any commits not present on the first {- Checks if the second branch has any commits not present on the first
- branch. -} - branch. -}