diff options
Diffstat (limited to 'Assistant/Threads/Merger.hs')
-rw-r--r-- | Assistant/Threads/Merger.hs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/Assistant/Threads/Merger.hs b/Assistant/Threads/Merger.hs index ff98cce5f..5d40edea7 100644 --- a/Assistant/Threads/Merger.hs +++ b/Assistant/Threads/Merger.hs @@ -1,6 +1,6 @@ {- git-annex assistant git merge thread - - - Copyright 2012 Joey Hess <id@joeyh.name> + - Copyright 2012-2017 Joey Hess <id@joeyh.name> - - Licensed under the GNU GPL version 3 or higher. -} @@ -15,6 +15,7 @@ import Utility.DirWatcher.Types import qualified Annex.Branch import qualified Git import qualified Git.Branch +import qualified Git.Ref import qualified Command.Sync {- This thread watches for changes to .git/refs/, and handles incoming @@ -63,19 +64,14 @@ onChange file diverged <- liftAnnex Annex.Branch.forceUpdate when diverged $ queueDeferredDownloads "retrying deferred download" Later - -- Merge only from /synced/ branches, which are pushed by git-annex - -- sync and by remote instances of the assistant. - -- It would be nice to merge other remote tracking branches, - -- but it's hard to get an efficient list of them (git remote -r) - | "/synced/" `isInfixOf` file = mergecurrent - | otherwise = noop + | otherwise = mergecurrent where changedbranch = fileToBranch file mergecurrent = mergecurrent' =<< liftAnnex (join Command.Sync.getCurrBranch) mergecurrent' currbranch@(Just b, _) - | equivBranches changedbranch b = + | changedbranch `isRelatedTo` b = whenM (liftAnnex $ inRepo $ Git.Branch.changed b changedbranch) $ do debug [ "merging", Git.fromRef changedbranch @@ -88,10 +84,17 @@ onChange file changedbranch mergecurrent' _ = noop -equivBranches :: Git.Ref -> Git.Ref -> Bool -equivBranches x y = base x == base y +{- Is the first branch a synced branch or remote tracking branch related + - to the second branch, which should be merged into it? -} +isRelatedTo :: Git.Ref -> Git.Ref -> Bool +isRelatedTo x y + | basex /= takeDirectory basex ++ "/" ++ basey = False + | "/synced/" `isInfixOf` Git.fromRef x = True + | "refs/remotes/" `isPrefixOf` Git.fromRef x = True + | otherwise = False where - base = takeFileName . Git.fromRef + basex = Git.fromRef $ Git.Ref.base x + basey = Git.fromRef $ Git.Ref.base y isAnnexBranch :: FilePath -> Bool isAnnexBranch f = n `isSuffixOf` f |