summaryrefslogtreecommitdiff
path: root/Assistant/Threads/Merger.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-09-16 18:53:13 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-09-16 19:41:26 -0400
commit6cddda4143d00e3a153d9cfbb567b11306677d11 (patch)
tree44ceb6eda48515be4030016c2aa4c1d406f39aea /Assistant/Threads/Merger.hs
parent601ee470af277ad3d0041b6ce425d808075dc997 (diff)
make the merger merge any equivilant sync branch into the current branch
Not just synced/master, but synced/UUID/master, for example
Diffstat (limited to 'Assistant/Threads/Merger.hs')
-rw-r--r--Assistant/Threads/Merger.hs43
1 files changed, 30 insertions, 13 deletions
diff --git a/Assistant/Threads/Merger.hs b/Assistant/Threads/Merger.hs
index 9ed744808..56b0abb80 100644
--- a/Assistant/Threads/Merger.hs
+++ b/Assistant/Threads/Merger.hs
@@ -11,10 +11,10 @@ import Assistant.Common
import Assistant.ThreadedMonad
import Utility.DirWatcher
import Utility.Types.DirWatcher
+import qualified Annex.Branch
import qualified Git
import qualified Git.Merge
import qualified Git.Branch
-import qualified Command.Sync
thisThread :: ThreadName
thisThread = "Merger"
@@ -67,16 +67,33 @@ onErr _ msg _ = error msg
onAdd :: Handler
onAdd g file _
| ".lock" `isSuffixOf` file = noop
- | otherwise = do
- let changedbranch = Git.Ref $
- "refs" </> "heads" </> takeFileName file
- current <- Git.Branch.current g
- when (Just changedbranch == current) $ do
- liftIO $ debug thisThread
- [ "merging changes into"
- , show current
- ]
- void $ mergeBranch changedbranch g
+ | isAnnexBranch file = noop
+ | "/synced/" `isInfixOf` file = go =<< Git.Branch.current g
+ | otherwise = noop
+ where
+ changedbranch = fileToBranch file
+ go (Just current)
+ | equivBranches changedbranch current = do
+ liftIO $ debug thisThread
+ [ "merging"
+ , show changedbranch
+ , "into"
+ , show current
+ ]
+ void $ Git.Merge.mergeNonInteractive changedbranch g
+ go _ = noop
+
+equivBranches :: Git.Ref -> Git.Ref -> Bool
+equivBranches x y = base x == base y
+ where
+ base = takeFileName . show
-mergeBranch :: Git.Ref -> Git.Repo -> IO Bool
-mergeBranch = Git.Merge.mergeNonInteractive . Command.Sync.syncBranch
+isAnnexBranch :: FilePath -> Bool
+isAnnexBranch f = n `isSuffixOf` f
+ where
+ n = "/" ++ show Annex.Branch.name
+
+fileToBranch :: FilePath -> Git.Ref
+fileToBranch f = Git.Ref $ "refs" </> "heads" </> base
+ where
+ base = Prelude.last $ split "/refs/heads/" f