Deal with git check-attr -z output format change in git 1.8.5.

I have not actually tested with 1.8.5, which is not yet relesaed, but
git.git commit f7cd8c50b9ab83e084e8f52653ecc8d90665eef2 changes -z
to also apply to output, without regards to back-compat. (But with pretty
good reasons.)

New code should work with both versions, by fingerprinting for NULs and
newlines.
This commit is contained in:
Joey Hess 2013-10-15 16:04:26 -04:00
parent ad38c2c8e3
commit bac078742d
3 changed files with 39 additions and 5 deletions

View file

@ -13,6 +13,8 @@ import Git.Command
import qualified Git.BuildVersion
import qualified Utility.CoProcess as CoProcess
import System.IO.Error
type CheckAttrHandle = (CoProcess.CoProcessHandle, [Attr], String)
type Attr = String
@ -37,16 +39,41 @@ checkAttrStop (h, _, _) = CoProcess.stop h
{- Gets an attribute of a file. -}
checkAttr :: CheckAttrHandle -> Attr -> FilePath -> IO String
checkAttr (h, attrs, cwd) want file = do
pairs <- CoProcess.query h send receive
pairs <- CoProcess.query h send (receive "")
let vals = map snd $ filter (\(attr, _) -> attr == want) pairs
case vals of
[v] -> return v
_ -> error $ "unable to determine " ++ want ++ " attribute of " ++ file
where
send to = hPutStr to $ file' ++ "\0"
receive from = forM attrs $ \attr -> do
l <- hGetLine from
return (attr, attrvalue attr l)
receive c from = do
s <- hGetSomeString from 1024
if null s
then eofError
else do
let v = c ++ s
maybe (receive v from) return (parse v)
eofError = ioError $ mkIOError userErrorType "git check-attr EOF" Nothing Nothing
parse s
-- new null separated output
| '\0' `elem` s = if "\0" `isSuffixOf` s
then
let bits = segment (== '\0') s
in if length bits == numattrs * 3
then Just $ getattrvalues bits []
else Nothing -- more attributes to come
else Nothing -- output incomplete
-- old one line per value output
| otherwise = if "\n" `isSuffixOf` s
then
let ls = lines s
in if length ls == numattrs
then Just $ map (\(attr, val) -> (attr, oldattrvalue attr val))
(zip attrs ls)
else Nothing -- more attributes to come
else Nothing -- line incomplete
numattrs = length attrs
{- Before git 1.7.7, git check-attr worked best with
- absolute filenames; using them worked around some bugs
- with relative filenames.
@ -58,7 +85,9 @@ checkAttr (h, attrs, cwd) want file = do
file'
| oldgit = absPathFrom cwd file
| otherwise = relPathDirToFile cwd $ absPathFrom cwd file
attrvalue attr l = end bits !! 0
oldattrvalue attr l = end bits !! 0
where
bits = split sep l
sep = ": " ++ attr ++ ": "
getattrvalues (_filename:attr:val:rest) c = getattrvalues rest ((attr,val):c)
getattrvalues _ c = c

1
debian/changelog vendored
View file

@ -20,6 +20,7 @@ git-annex (4.20131003) UNRELEASED; urgency=low
* Fixed handling of URL keys that have no recorded size.
* status: Fix a crash if a temp file went away while its size was
being checked for status.
* Deal with git check-attr -z output format change in git 1.8.5.
-- Joey Hess <joeyh@debian.org> Thu, 03 Oct 2013 15:41:24 -0400

View file

@ -274,3 +274,7 @@ The same happens when I git annex add in /data/data/ga.androidterm/anntmp - so i
# End of transcript or log.
"""]]
> I have updated git-annex to work with the new git, which will be 1.8.5.
> This fix should appear in the android autobuild within an hour if you
> want to try it. [[done]] --[[Joey]]