diff options
author | 2011-12-22 14:59:25 -0400 | |
---|---|---|
committer | 2011-12-22 15:01:13 -0400 | |
commit | 5a275a3f5d79977170a70b3e3ee16e38ac32916f (patch) | |
tree | 8817cfabed6067b21476290f6c6a00aba8fc1775 /Git/Version.hs | |
parent | 7892397020fe345886ef9aa84a6c1580ebee5348 (diff) |
Can now be built with older git versions (before 1.7.7); the resulting binary should only be used with old git.
Remove git old version check from configure, and use the git version
it was built against in the git check-attr code.
Diffstat (limited to 'Git/Version.hs')
-rw-r--r-- | Git/Version.hs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Git/Version.hs b/Git/Version.hs new file mode 100644 index 000000000..c8bc121d6 --- /dev/null +++ b/Git/Version.hs @@ -0,0 +1,38 @@ +{- git version checking + - + - Copyright 2011 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +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 + +older :: String -> Bool +older v = normalize version < normalize v + +{- 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 "." + 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 |