summaryrefslogtreecommitdiff
path: root/Command/Sync.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-30 18:04:01 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-30 18:04:01 -0400
commitf2fa29bf3bb3d54b9c4d789b36d04ba693dee53a (patch)
treea23d3af141c1e716a23dc1fac77a38c5d55d1b78 /Command/Sync.hs
parent9d85baa31425e04f0eb79e43c09c8d4e4a414c6b (diff)
check if branches are up-to-date before merging, pushing
This optimises away the need to run anything in some common cases. It's particularly useful on push; no need to push if the tracking branch we just pulled is the same as the branch we're going to push.
Diffstat (limited to 'Command/Sync.hs')
-rw-r--r--Command/Sync.hs48
1 files changed, 28 insertions, 20 deletions
diff --git a/Command/Sync.hs b/Command/Sync.hs
index 790bf53b5..423a772f3 100644
--- a/Command/Sync.hs
+++ b/Command/Sync.hs
@@ -15,6 +15,7 @@ import Command
import qualified Remote
import qualified Annex.Branch
import qualified Git.Command
+import qualified Git.Branch
import qualified Git.Config
import qualified Git.Ref
import qualified Git
@@ -34,7 +35,7 @@ seek args = do
return $ concat $
[ [ commit ]
, [ mergeLocal branch ]
- , [ update remote branch | remote <- remotes ]
+ , [ pullRemote remote branch | remote <- remotes ]
, [ mergeAnnex ]
, [ pushLocal syncbranch ]
, [ pushRemote remote branch syncbranch | remote <- remotes ]
@@ -69,10 +70,13 @@ commit = do
return True
mergeLocal :: Git.Ref -> CommandStart
-mergeLocal branch = do
- let mergebranch = Git.Ref.under "refs/heads/synced" branch
- showStart "merge" $ Git.Ref.describe mergebranch
- next $ next $ mergeFromIfExists mergebranch
+mergeLocal branch = go =<< inRepo (Git.Branch.changed branch mergebranch)
+ where
+ mergebranch = Git.Ref.under "refs/heads/synced" branch
+ go False = stop
+ go True = do
+ showStart "merge" $ Git.Ref.describe mergebranch
+ next $ next $ mergeFromIfExists mergebranch
pushLocal :: Git.Ref -> CommandStart
pushLocal syncbranch = go =<< inRepo (Git.Ref.exists syncbranch)
@@ -99,9 +103,9 @@ mergeFromIfExists branch = go =<< inRepo (Git.Ref.exists branch)
" does not exist, not merging"
return False
-update :: Remote.Remote Annex -> Git.Ref -> CommandStart
-update remote branch = do
- showStart "update" (Remote.name remote)
+pullRemote :: Remote.Remote Annex -> Git.Ref -> CommandStart
+pullRemote remote branch = do
+ showStart "pull" (Remote.name remote)
next $ do
checkRemote remote
showOutput
@@ -115,18 +119,22 @@ mergeRemote remote = mergeFromIfExists .
Git.Ref.under ("refs/remotes/" ++ Remote.name remote ++ "/synced")
pushRemote :: Remote.Remote Annex -> Git.Ref -> Git.Ref -> CommandStart
-pushRemote remote branch syncbranch = do
- showStart "push" (Remote.name remote)
- let syncbranchRemote = Git.Ref.under
- ("refs/remotes/" ++ Remote.name remote) syncbranch
- let refspec = show (Git.Ref.base branch) ++ ":" ++ show (Git.Ref.base syncbranch)
- ex <- inRepo $ Git.Ref.exists syncbranchRemote
- next $ next $ do
- showOutput
- inRepo $ Git.Command.runBool "push" $
- [ Param (Remote.name remote)
- , Param (show $ Annex.Branch.name) ] ++
- [ Param refspec | ex ]
+pushRemote remote branch syncbranch = go =<< newer
+ where
+ newer = inRepo $ Git.Branch.changed syncbranchRemote syncbranch
+ go False = stop
+ go True = do
+ showStart "push" (Remote.name remote)
+ ex <- inRepo $ Git.Ref.exists syncbranchRemote
+ next $ next $ do
+ showOutput
+ inRepo $ Git.Command.runBool "push" $
+ [ Param (Remote.name remote)
+ , Param (show $ Annex.Branch.name) ] ++
+ [ Param refspec | ex ]
+ refspec = show (Git.Ref.base branch) ++ ":" ++ show (Git.Ref.base syncbranch)
+ syncbranchRemote = Git.Ref.under
+ ("refs/remotes/" ++ Remote.name remote) syncbranch
currentBranch :: Annex Git.Ref
currentBranch = Git.Ref . firstLine . L.unpack <$>