summaryrefslogtreecommitdiff
path: root/Command/Sync.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-02-01 10:49:50 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-02-01 10:49:50 -0400
commit5cfb63e170954b2dc48d4dddc18bc2cd138c2cdf (patch)
tree5d5c651577374b65c2c5ce61a34505f6ce1647a1 /Command/Sync.hs
parent6f622c6043ad8db9f27a16020c371af68506e8e7 (diff)
sync --content: Re-pull from remotes after downloading content, since that can take a while and other changes may be pushed in the meantime.
Diffstat (limited to 'Command/Sync.hs')
-rw-r--r--Command/Sync.hs32
1 files changed, 25 insertions, 7 deletions
diff --git a/Command/Sync.hs b/Command/Sync.hs
index 5719f5b70..04d91adee 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