From 15ac2ea4de0bd6fa37e27632b8c8b282263223f2 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 1 Feb 2014 10:49:50 -0400 Subject: [PATCH] sync --content: Re-pull from remotes after downloading content, since that can take a while and other changes may be pushed in the meantime. --- Command/Sync.hs | 32 +++++++++++++++++++++++++------- debian/changelog | 3 +++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Command/Sync.hs b/Command/Sync.hs index 5719f5b702..04d91adee8 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -86,7 +86,16 @@ seek rs = do , [ mergeAnnex ] ] whenM (Annex.getFlag $ optionName contentOption) $ - seekSyncContent dataremotes + whenM (seekSyncContent dataremotes) $ do + -- Transferring content can take a while, + -- and other changes can be pushed to the git-annex + -- branch on the remotes in the meantime, so pull + -- and merge again to avoid our push overwriting + -- those changes. + seekActions $ return $ concat + [ map (withbranch . pullRemote) gitremotes + , [ commitAnnex, mergeAnnex ] + ] seekActions $ return $ concat [ [ withbranch pushLocal ] , map (withbranch . pushRemote) gitremotes @@ -172,9 +181,6 @@ mergeLocal (Just branch) = go =<< needmerge pushLocal :: Maybe Git.Ref -> CommandStart pushLocal Nothing = stop pushLocal (Just branch) = do - -- In case syncing content made changes to the git-annex branch, - -- commit it. - Annex.Branch.commit "update" -- Update the sync branch to match the new state of the branch inRepo $ updateBranch $ syncBranch branch -- In direct mode, we're operating on some special direct mode @@ -288,6 +294,11 @@ pushBranch remote branch g = tryIO (directpush g) `after` syncpush g , show $ Git.Ref.base $ syncBranch b ] +commitAnnex :: CommandStart +commitAnnex = do + Annex.Branch.commit "update" + stop + mergeAnnex :: CommandStart mergeAnnex = do void Annex.Branch.forceUpdate @@ -498,11 +509,18 @@ newer remote b = do - - Drop it from each remote that has it, where it's not preferred content - (honoring numcopies). + - + - If any file movements were generated, returns true. -} -seekSyncContent :: [Remote] -> Annex () -seekSyncContent rs = mapM_ go =<< seekHelper LsFiles.inRepo [] +seekSyncContent :: [Remote] -> Annex Bool +seekSyncContent rs = do + mvar <- liftIO $ newEmptyMVar + mapM_ (go mvar) =<< seekHelper LsFiles.inRepo [] + liftIO $ not <$> isEmptyMVar mvar where - go f = ifAnnexed f (syncFile rs f) noop + go mvar f = ifAnnexed f + (\v -> void (liftIO (tryPutMVar mvar ())) >> syncFile rs f v) + noop syncFile :: [Remote] -> FilePath -> (Key, Backend) -> Annex () syncFile rs f (k, _) = do diff --git a/debian/changelog b/debian/changelog index de5229ddb6..2f979aa698 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,6 +9,9 @@ git-annex (5.20140128) UNRELEASED; urgency=medium * sync --content: Honor annex-ignore configuration. * sync: Don't try to sync with xmpp remotes, which are only currently supported when using the assistant. + * sync --content: Re-pull from remotes after downloading content, + since that can take a while and other changes may be pushed in the + meantime. -- Joey Hess Tue, 28 Jan 2014 13:57:19 -0400