Add a simple script which drives 'kdiff3' through a large source tree
(3 such trees, really). This makes it easy to do 3 way merges of such
trees and easily stop and resume without losing work.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6312 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/auxprogs/Merge3Way.hs b/auxprogs/Merge3Way.hs
new file mode 100644
index 0000000..5ca6f06
--- /dev/null
+++ b/auxprogs/Merge3Way.hs
@@ -0,0 +1,66 @@
+
+module Main where
+
+import IO
+import Directory
+import System
+
+dirAA = "in-AAcommon-6077-1660"
+dirBB = "in-BBtrunk"
+dirCC = "in-CCaixbranch"
+dirRR = "RESULT"
+
+maybe_do :: String -> IO ()
+maybe_do f
+ = let r = dirRR ++ "/" ++ f
+ a = dirAA ++ "/" ++ f
+ b = dirBB ++ "/" ++ f
+ c = dirCC ++ "/" ++ f
+ in
+ do x <- doesFileExist r
+ if x
+ then hPutStrLn stderr ("done: " ++ f)
+ else
+ do hPutStrLn stderr (" do: " ++ f)
+ xx <- system ("mkdir -p " ++ basename r)
+ rs <- merge3 r a b c
+ hPutStrLn stderr (rs ++ f)
+
+
+merge3 :: String -> String -> String -> String -> IO String
+merge3 r a b c
+ = do ca <- readFile a
+ cb <- readFile b
+ cc <- readFile c
+ let same = identical3 ca cb cc
+ if same
+ then
+ do ec <- system ("/bin/cp " ++ a ++ " " ++ r)
+ if ec == ExitSuccess
+ then return "COPY: "
+ else barf "/bin/cp failed"
+ else
+ do ec <- system ("kdiff3 -m -o " ++ r ++ " -b "
+ ++ a ++ " " ++ b ++ " " ++ c ++ " &> /dev/null" )
+ if ec == ExitSuccess
+ then return " ok: "
+ else barf "kdiff3 failed"
+
+barf :: String -> IO a
+barf who
+ = do hPutStrLn stderr ("FAIL: " ++ who)
+ exitWith ExitSuccess
+
+identical3 :: String -> String -> String -> Bool
+identical3 [] [] [] = True
+identical3 (x:xs) (y:ys) (z:zs)
+ = x == y && y == z && identical3 xs ys zs
+identical3 _ _ _ = False
+
+main :: IO ()
+main
+ = do t <- readFile "FILEScba"
+ let fs = lines t
+ mapM_ maybe_do fs
+
+basename = reverse . drop 1 . dropWhile (/= '/') . reverse