Commits

John Lenz  committed f3fd5ec

Add version checking for the command server

  • Participants
  • Parent commits 51fc66a

Comments (0)

Files changed (1)

File Data/FileStore/MercurialCommandServer.hs

 import Data.Bits (shiftL, shiftR, (.|.))
 import Data.FileStore.Utils (runShellCommand)
 import Data.IORef
-import Data.List (intercalate)
+import Data.List (intercalate, isPrefixOf)
+import Data.List.Split (splitOn)
 import Data.Typeable (Typeable)
 import Data.Word (Word32)
 import System.Exit (ExitCode(..))
 
 -- | Check if the mercurial version supports servers
 checkVersion :: IO Bool
-checkVersion = return True
+checkVersion = do
+    (status,_,out) <- runShellCommand "." Nothing "hg" ["version", "-q"]
+    case status of
+      ExitFailure _ -> return False
+      ExitSuccess   -> return $ parseVersion (LUTF8.toString out) >= [1,9]
+
+-- | hg version -q returns something like "Mercurial Distributed SCM (version 1.9.1)"
+--   This function returns the list [1,9,1]
+parseVersion :: String -> [Int]
+parseVersion b = if starts then verLst else [0]
+  where msg = "Mercurial Distributed SCM (version "
+        starts = isPrefixOf msg b
+        ver    = takeWhile (/= ')') $ drop (length msg) b
+        verLst = map read $ splitOn "." ver