From 631c8d3e5b2325dd2c6471eb42dc789f8d1fed9b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 16 Nov 2020 15:13:48 -0400 Subject: [PATCH] avoid redundant adjusted branch update in sync sync still does update it if the config would otherwise not, since it already did. --- Annex/AdjustedBranch.hs | 26 ++++++++++++++++---------- Command/Sync.hs | 12 ++++++------ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Annex/AdjustedBranch.hs b/Annex/AdjustedBranch.hs index ea79a7f180..10715bc227 100644 --- a/Annex/AdjustedBranch.hs +++ b/Annex/AdjustedBranch.hs @@ -21,8 +21,8 @@ module Annex.AdjustedBranch ( fromAdjustedBranch, getAdjustment, enterAdjustedBranch, - updateAdjustedBranch, adjustedBranchRefresh, + adjustedBranchRefreshFull, adjustBranch, adjustTree, adjustToCrippledFileSystem, @@ -296,7 +296,7 @@ adjustedBranchRefresh _af a = do ifM (checkcounter n) ( update adj origbranch , Annex.addCleanup AdjustedBranchUpdate $ - update adj origbranch + adjustedBranchRefreshFull adj origbranch ) _ -> return () @@ -309,20 +309,26 @@ adjustedBranchRefresh _af a = do !c' = if enough then 0 else c !s' = s { Annex.adjustedbranchrefreshcounter = c' } in pure (s', enough) - - -- TODO This is very slow when run a lot of times. - -- Incrementally adjust only the AssociatedFile. - -- However, this should be run once at shutdown then, - -- because other files than the provided AssociatedFile - -- can need to be updated in some edge cases. + update adj origbranch = do -- Flush the queue, to make any pending changes be written -- out to disk. But mostly so any pointer files -- restagePointerFile was called on get updated so git -- checkout won't fall over. Annex.Queue.flush - let adjbranch = originalToAdjusted origbranch adj - void $ updateAdjustedBranch adj adjbranch origbranch + -- This is slow, it would be better to incrementally + -- adjust the AssociatedFile, and only call this once + -- at shutdown to handle cases where not all + -- AssociatedFiles are known. + adjustedBranchRefreshFull adj origbranch + +{- Slow, but more dependable version of adjustedBranchRefresh that + - does not rely on all AssociatedFiles being known. -} +adjustedBranchRefreshFull :: Adjustment -> OrigBranch -> Annex () +adjustedBranchRefreshFull adj origbranch = do + let adjbranch = originalToAdjusted origbranch adj + unlessM (updateAdjustedBranch adj adjbranch origbranch) $ + warning $ unwords [ "Updating adjusted branch failed." ] adjustToCrippledFileSystem :: Annex () adjustToCrippledFileSystem = do diff --git a/Command/Sync.hs b/Command/Sync.hs index 966cba340e..fb37a087e5 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -407,17 +407,17 @@ updateBranches (Nothing, _) = noop updateBranches (Just branch, madj) = do -- When in an adjusted branch, propigate any changes made to it -- back to the original branch. The adjusted branch may also need - -- to be updated, if the adjustment is not stable. + -- to be updated, if the adjustment is not stable, and the usual + -- configuration does not update it. case madj of Nothing -> noop Just adj -> do let origbranch = branch propigateAdjustedCommits origbranch adj - unless (adjustmentIsStable adj) $ do - showSideAction "updating adjusted branch" - let adjbranch = originalToAdjusted origbranch adj - unlessM (updateAdjustedBranch adj adjbranch origbranch) $ - warning $ unwords [ "Updating adjusted branch failed." ] + unless (adjustmentIsStable adj) $ + annexAdjustedBranchRefresh <$> Annex.getGitConfig >>= \case + 0 -> adjustedBranchRefreshFull adj origbranch + _ -> return () -- Update the sync branch to match the new state of the branch inRepo $ updateBranch (syncBranch branch) branch