summaryrefslogtreecommitdiff
path: root/Git/Version.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-08-02 18:31:01 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-08-02 18:32:26 -0400
commitaddc505584876cca50ccdcd1c982e9a5e10ec9b1 (patch)
tree9da1fe90f8d96a038f939a9fc05d64c7af7e3369 /Git/Version.hs
parent5921e627d75758101ccb38f76c83c3917ae897b7 (diff)
better git version checking
Diffstat (limited to 'Git/Version.hs')
-rw-r--r--Git/Version.hs35
1 files changed, 20 insertions, 15 deletions
diff --git a/Git/Version.hs b/Git/Version.hs
index 44385d9b8..5ad1d5959 100644
--- a/Git/Version.hs
+++ b/Git/Version.hs
@@ -1,6 +1,6 @@
-{- git version checking
+{- git versions
-
- - Copyright 2011 Joey Hess <joey@kitenet.net>
+ - Copyright 2011, 2013 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -8,24 +8,29 @@
module Git.Version where
import Common
-import qualified Build.SysConfig
-{- Using the version it was configured for avoids running git to check its
- - version, at the cost that upgrading git won't be noticed.
- - This is only acceptable because it's rare that git's version influences
- - code's behavior. -}
-version :: String
-version = Build.SysConfig.gitversion
+data GitVersion = GitVersion String Integer
+ deriving (Eq)
-older :: String -> Bool
-older v = normalize version < normalize v
+instance Ord GitVersion where
+ compare (GitVersion _ x) (GitVersion _ y) = compare x y
+
+instance Show GitVersion where
+ show (GitVersion s _) = s
+
+installed :: IO GitVersion
+installed = normalize . extract <$> readProcess "git" ["--version"]
+ where
+ extract s = case lines s of
+ [] -> ""
+ (l:_) -> unwords $ drop 2 $ words l
{- To compare dotted versions like 1.7.7 and 1.8, they are normalized to
- a somewhat arbitrary integer representation. -}
-normalize :: String -> Integer
-normalize = sum . mult 1 . reverse .
- extend precision . take precision .
- map readi . split "."
+normalize :: String -> GitVersion
+normalize v = GitVersion v $
+ sum $ mult 1 $ reverse $ extend precision $ take precision $
+ map readi $ split "." v
where
extend n l = l ++ replicate (n - length l) 0
mult _ [] = []