summaryrefslogtreecommitdiff
path: root/Git/Version.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2015-01-06 19:02:48 -0400
committerJoey Hess <joeyh@joeyh.name>2015-01-06 19:02:48 -0400
commit9af9872f0f54d5d4af2aed3d08eef9ab67012261 (patch)
tree4849db9d9bfa08603a4d0913bb1fbbf14213b4a4 /Git/Version.hs
parent46b630831bda126b6f4ab723229e32c1677ae6d0 (diff)
downloadgit-repair-9af9872f0f54d5d4af2aed3d08eef9ab67012261.tar.gz
Merge from git-annex.
Diffstat (limited to 'Git/Version.hs')
-rw-r--r--Git/Version.hs37
1 files changed, 12 insertions, 25 deletions
diff --git a/Git/Version.hs b/Git/Version.hs
index 5c61f85..73ce2f8 100644
--- a/Git/Version.hs
+++ b/Git/Version.hs
@@ -5,18 +5,17 @@
- Licensed under the GNU GPL version 3 or higher.
-}
-module Git.Version where
+module Git.Version (
+ installed,
+ older,
+ normalize,
+ GitVersion,
+) where
import Common
+import Utility.DottedVersion
-data GitVersion = GitVersion String Integer
- deriving (Eq)
-
-instance Ord GitVersion where
- compare (GitVersion _ x) (GitVersion _ y) = compare x y
-
-instance Show GitVersion where
- show (GitVersion s _) = s
+type GitVersion = DottedVersion
installed :: IO GitVersion
installed = normalize . extract <$> readProcess "git" ["--version"]
@@ -25,19 +24,7 @@ installed = normalize . extract <$> readProcess "git" ["--version"]
[] -> ""
(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 -> 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 _ [] = []
- mult n (x:xs) = (n*x) : mult (n*10^width) xs
- readi :: String -> Integer
- readi s = case reads s of
- ((x,_):_) -> x
- _ -> 0
- precision = 10 -- number of segments of the version to compare
- width = length "yyyymmddhhmmss" -- maximum width of a segment
+older :: String -> IO Bool
+older n = do
+ v <- installed
+ return $ v < normalize n