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.
This commit is contained in:
Joey Hess 2011-12-30 18:04:01 -04:00
parent 9d85baa314
commit f2fa29bf3b

View file

@ -15,6 +15,7 @@ import Command
import qualified Remote import qualified Remote
import qualified Annex.Branch import qualified Annex.Branch
import qualified Git.Command import qualified Git.Command
import qualified Git.Branch
import qualified Git.Config import qualified Git.Config
import qualified Git.Ref import qualified Git.Ref
import qualified Git import qualified Git
@ -34,7 +35,7 @@ seek args = do
return $ concat $ return $ concat $
[ [ commit ] [ [ commit ]
, [ mergeLocal branch ] , [ mergeLocal branch ]
, [ update remote branch | remote <- remotes ] , [ pullRemote remote branch | remote <- remotes ]
, [ mergeAnnex ] , [ mergeAnnex ]
, [ pushLocal syncbranch ] , [ pushLocal syncbranch ]
, [ pushRemote remote branch syncbranch | remote <- remotes ] , [ pushRemote remote branch syncbranch | remote <- remotes ]
@ -69,8 +70,11 @@ commit = do
return True return True
mergeLocal :: Git.Ref -> CommandStart mergeLocal :: Git.Ref -> CommandStart
mergeLocal branch = do mergeLocal branch = go =<< inRepo (Git.Branch.changed branch mergebranch)
let mergebranch = Git.Ref.under "refs/heads/synced" branch where
mergebranch = Git.Ref.under "refs/heads/synced" branch
go False = stop
go True = do
showStart "merge" $ Git.Ref.describe mergebranch showStart "merge" $ Git.Ref.describe mergebranch
next $ next $ mergeFromIfExists mergebranch next $ next $ mergeFromIfExists mergebranch
@ -99,9 +103,9 @@ mergeFromIfExists branch = go =<< inRepo (Git.Ref.exists branch)
" does not exist, not merging" " does not exist, not merging"
return False return False
update :: Remote.Remote Annex -> Git.Ref -> CommandStart pullRemote :: Remote.Remote Annex -> Git.Ref -> CommandStart
update remote branch = do pullRemote remote branch = do
showStart "update" (Remote.name remote) showStart "pull" (Remote.name remote)
next $ do next $ do
checkRemote remote checkRemote remote
showOutput showOutput
@ -115,11 +119,12 @@ mergeRemote remote = mergeFromIfExists .
Git.Ref.under ("refs/remotes/" ++ Remote.name remote ++ "/synced") Git.Ref.under ("refs/remotes/" ++ Remote.name remote ++ "/synced")
pushRemote :: Remote.Remote Annex -> Git.Ref -> Git.Ref -> CommandStart pushRemote :: Remote.Remote Annex -> Git.Ref -> Git.Ref -> CommandStart
pushRemote remote branch syncbranch = do 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) 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 ex <- inRepo $ Git.Ref.exists syncbranchRemote
next $ next $ do next $ next $ do
showOutput showOutput
@ -127,6 +132,9 @@ pushRemote remote branch syncbranch = do
[ Param (Remote.name remote) [ Param (Remote.name remote)
, Param (show $ Annex.Branch.name) ] ++ , Param (show $ Annex.Branch.name) ] ++
[ Param refspec | ex ] [ 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 :: Annex Git.Ref
currentBranch = Git.Ref . firstLine . L.unpack <$> currentBranch = Git.Ref . firstLine . L.unpack <$>