wrote checkAttr

This commit is contained in:
Joey Hess 2010-11-01 18:24:19 -04:00
parent 899a86f8f9
commit ab3294f1dd

View file

@ -35,7 +35,8 @@ module GitRepo (
repoRemoteName, repoRemoteName,
inRepo, inRepo,
notInRepo, notInRepo,
stagedFiles stagedFiles,
checkAttr
) where ) where
import Monad (unless) import Monad (unless)
@ -145,6 +146,26 @@ attributes repo
| bare repo = (workTree repo) ++ "/info/.gitattributes" | bare repo = (workTree repo) ++ "/info/.gitattributes"
| otherwise = (workTree repo) ++ "/.gitattributes" | otherwise = (workTree repo) ++ "/.gitattributes"
{- Looks up a gitattributes value for each file in a list. -}
checkAttr :: Repo -> String -> [FilePath] -> IO [(FilePath, String)]
checkAttr repo attr files = do
(pid, fromh, toh) <- hPipeBoth "git" $
gitCommandLine repo ["check-attr", attr, "-z", "--stdin"]
-- git-check-attr reads all its stdin before outputting anything,
-- so we don't need to worry about deadlock
hPutStr toh files0
hClose toh
c <- hGetContentsStrict fromh
hClose fromh
forceSuccess pid
return $ map topair $ lines c
where
files0 = join "\0" files
topair l = (bits !! 0, join sep $ drop 1 $ bits)
where
bits = split sep l
sep = ": " ++ attr ++ ": "
{- Path to a repository's .git directory, relative to its workTree. -} {- Path to a repository's .git directory, relative to its workTree. -}
gitDir :: Repo -> String gitDir :: Repo -> String
gitDir repo gitDir repo