diff options
Diffstat (limited to 'Git')
-rw-r--r-- | Git/BuildVersion.hs | 21 | ||||
-rw-r--r-- | Git/CheckAttr.hs | 4 | ||||
-rw-r--r-- | Git/Merge.hs | 2 | ||||
-rw-r--r-- | Git/Version.hs | 35 |
4 files changed, 44 insertions, 18 deletions
diff --git a/Git/BuildVersion.hs b/Git/BuildVersion.hs new file mode 100644 index 000000000..832ee8ab7 --- /dev/null +++ b/Git/BuildVersion.hs @@ -0,0 +1,21 @@ +{- git build version + - + - Copyright 2011 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Git.BuildVersion where + +import Git.Version +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. -} +buildVersion :: GitVersion +buildVersion = normalize Build.SysConfig.gitversion + +older :: String -> Bool +older n = buildVersion < normalize n diff --git a/Git/CheckAttr.hs b/Git/CheckAttr.hs index 0bf6a3931..24fa2be87 100644 --- a/Git/CheckAttr.hs +++ b/Git/CheckAttr.hs @@ -10,7 +10,7 @@ module Git.CheckAttr where import Common import Git import Git.Command -import qualified Git.Version +import qualified Git.BuildVersion import qualified Utility.CoProcess as CoProcess type CheckAttrHandle = (CoProcess.CoProcessHandle, [Attr], String) @@ -54,7 +54,7 @@ checkAttr (h, attrs, cwd) want file = do - With newer git, git check-attr chokes on some absolute - filenames, and the bugs that necessitated them were fixed, - so use relative filenames. -} - oldgit = Git.Version.older "1.7.7" + oldgit = Git.BuildVersion.older "1.7.7" file' | oldgit = absPathFrom cwd file | otherwise = relPathDirToFile cwd $ absPathFrom cwd file diff --git a/Git/Merge.hs b/Git/Merge.hs index e70a71d64..f5791274f 100644 --- a/Git/Merge.hs +++ b/Git/Merge.hs @@ -10,7 +10,7 @@ module Git.Merge where import Common import Git import Git.Command -import Git.Version +import Git.BuildVersion {- Avoids recent git's interactive merge. -} mergeNonInteractive :: Ref -> Repo -> IO Bool 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 _ [] = [] |