summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-01 18:24:19 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-01 18:24:19 -0400
commitab3294f1dd734e7573c859e123158eda8e3551ac (patch)
tree3696ed983852d002ed40d6533bfa222d71ca04f5
parent899a86f8f9601e359a894fe2839dea9cf7f47def (diff)
wrote checkAttr
-rw-r--r--GitRepo.hs23
1 files changed, 22 insertions, 1 deletions
diff --git a/GitRepo.hs b/GitRepo.hs
index 505dd06eb..e8dd0a5dc 100644
--- a/GitRepo.hs
+++ b/GitRepo.hs
@@ -35,7 +35,8 @@ module GitRepo (
repoRemoteName,
inRepo,
notInRepo,
- stagedFiles
+ stagedFiles,
+ checkAttr
) where
import Monad (unless)
@@ -145,6 +146,26 @@ attributes repo
| bare repo = (workTree repo) ++ "/info/.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. -}
gitDir :: Repo -> String
gitDir repo