Check git version at runtime, rather than assuming it will be the same as the git version used at build time when running git-checkattr and git-branch remove.

It's ok to probe every time for git-branch remove because that's
run quite rarely. For git-checkattr, it's run only once, when
starting the --batch mode, and so again the overhead is pretty minimal.

This leaves 2 places where the build version is still used.
git merge might be interactive or fail if one skews, and --no-gpg-sign
might not be pased, or might be passed to a git that doesn't understand it
if the other skews. It seems a little expensive to check the git version
each time these are used.

This doesn't seem likely to cause many problems, at least compared with
check-attr hanging on skew.
This commit is contained in:
Joey Hess 2015-01-05 15:54:52 -04:00
parent bbd5812ab0
commit 4d786ebe4a
4 changed files with 27 additions and 16 deletions

View file

@ -10,12 +10,12 @@ module Git.CheckAttr where
import Common import Common
import Git import Git
import Git.Command import Git.Command
import qualified Git.BuildVersion import qualified Git.Version
import qualified Utility.CoProcess as CoProcess import qualified Utility.CoProcess as CoProcess
import System.IO.Error import System.IO.Error
type CheckAttrHandle = (CoProcess.CoProcessHandle, [Attr], String) type CheckAttrHandle = (CoProcess.CoProcessHandle, [Attr], Bool, String)
type Attr = String type Attr = String
@ -25,7 +25,8 @@ checkAttrStart :: [Attr] -> Repo -> IO CheckAttrHandle
checkAttrStart attrs repo = do checkAttrStart attrs repo = do
currdir <- getCurrentDirectory currdir <- getCurrentDirectory
h <- CoProcess.rawMode =<< gitCoProcessStart True params repo h <- CoProcess.rawMode =<< gitCoProcessStart True params repo
return (h, attrs, currdir) oldgit <- Git.Version.older "1.7.7"
return (h, attrs, oldgit, currdir)
where where
params = params =
[ Param "check-attr" [ Param "check-attr"
@ -34,11 +35,11 @@ checkAttrStart attrs repo = do
[ Param "--" ] [ Param "--" ]
checkAttrStop :: CheckAttrHandle -> IO () checkAttrStop :: CheckAttrHandle -> IO ()
checkAttrStop (h, _, _) = CoProcess.stop h checkAttrStop (h, _, _, _) = CoProcess.stop h
{- Gets an attribute of a file. -} {- Gets an attribute of a file. -}
checkAttr :: CheckAttrHandle -> Attr -> FilePath -> IO String checkAttr :: CheckAttrHandle -> Attr -> FilePath -> IO String
checkAttr (h, attrs, currdir) want file = do checkAttr (h, attrs, oldgit, currdir) want file = do
pairs <- CoProcess.query h send (receive "") pairs <- CoProcess.query h send (receive "")
let vals = map snd $ filter (\(attr, _) -> attr == want) pairs let vals = map snd $ filter (\(attr, _) -> attr == want) pairs
case vals of case vals of
@ -81,7 +82,6 @@ checkAttr (h, attrs, currdir) want file = do
- With newer git, git check-attr chokes on some absolute - With newer git, git check-attr chokes on some absolute
- filenames, and the bugs that necessitated them were fixed, - filenames, and the bugs that necessitated them were fixed,
- so use relative filenames. -} - so use relative filenames. -}
oldgit = Git.BuildVersion.older "1.7.7"
file' file'
| oldgit = absPathFrom currdir file | oldgit = absPathFrom currdir file
| otherwise = relPathDirToFile currdir $ absPathFrom currdir file | otherwise = relPathDirToFile currdir $ absPathFrom currdir file

View file

@ -13,15 +13,17 @@ import Common
import Git import Git
import Git.Types import Git.Types
import qualified Git.Command import qualified Git.Command
import qualified Git.BuildVersion import qualified Git.Version
remove :: RemoteName -> Repo -> IO () remove :: RemoteName -> Repo -> IO ()
remove remotename = Git.Command.run remove remotename r = do
[ Param "remote" old <- Git.Version.older "1.8.0"
-- name of this subcommand changed Git.Command.run
, Param $ [ Param "remote"
if Git.BuildVersion.older "1.8.0" -- name of this subcommand changed
then "rm" , Param $
else "remove" if old
, Param remotename then "rm"
] else "remove"
, Param remotename
] r

View file

@ -7,6 +7,7 @@
module Git.Version ( module Git.Version (
installed, installed,
older,
normalize, normalize,
GitVersion, GitVersion,
) where ) where
@ -22,3 +23,8 @@ installed = normalize . extract <$> readProcess "git" ["--version"]
extract s = case lines s of extract s = case lines s of
[] -> "" [] -> ""
(l:_) -> unwords $ drop 2 $ words l (l:_) -> unwords $ drop 2 $ words l
older :: String -> IO Bool
older n = do
v <- installed
return $ v < normalize n

3
debian/changelog vendored
View file

@ -9,6 +9,9 @@ git-annex (5.20141232) UNRELEASED; urgency=medium
* Android: Provide a version built with -fPIE -pie to support Android 5.0. * Android: Provide a version built with -fPIE -pie to support Android 5.0.
* sync: Fix an edge case where syncing in a bare repository would try to * sync: Fix an edge case where syncing in a bare repository would try to
merge and so fail. merge and so fail.
* Check git version at runtime, rather than assuming it will be the same
as the git version used at build time when running git-checkattr and
git-branch remove.
-- Joey Hess <id@joeyh.name> Fri, 02 Jan 2015 13:35:13 -0400 -- Joey Hess <id@joeyh.name> Fri, 02 Jan 2015 13:35:13 -0400