aboutsummaryrefslogtreecommitdiff
path: root/Git/CheckAttr.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-13 15:22:43 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-13 15:24:23 -0400
commit9db8ec210f8491de78cd7e83b94c50ead8049e72 (patch)
tree539d2a49f1599fdd4855570d046f710809062a8e /Git/CheckAttr.hs
parent25b2cc4148e4cc8f7435cdbcf4b124cc317c1305 (diff)
split out two more Git modules
Diffstat (limited to 'Git/CheckAttr.hs')
-rw-r--r--Git/CheckAttr.hs44
1 files changed, 44 insertions, 0 deletions
diff --git a/Git/CheckAttr.hs b/Git/CheckAttr.hs
new file mode 100644
index 000000000..e9269b1ed
--- /dev/null
+++ b/Git/CheckAttr.hs
@@ -0,0 +1,44 @@
+{- git check-attr interface
+ -
+ - Copyright 2010, 2011 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Git.CheckAttr where
+
+import System.Exit
+
+import Common
+import Git
+import qualified Git.Filename
+
+{- Efficiently looks up a gitattributes value for each file in a list. -}
+lookup :: String -> [FilePath] -> Repo -> IO [(FilePath, String)]
+lookup attr files repo = do
+ -- git check-attr needs relative filenames input; it will choke
+ -- on some absolute filenames. This also means it will output
+ -- all relative filenames.
+ cwd <- getCurrentDirectory
+ let relfiles = map (relPathDirToFile cwd . absPathFrom cwd) files
+ (_, fromh, toh) <- hPipeBoth "git" (toCommand params)
+ _ <- forkProcess $ do
+ hClose fromh
+ hPutStr toh $ join "\0" relfiles
+ hClose toh
+ exitSuccess
+ hClose toh
+ (map topair . lines) <$> hGetContents fromh
+ where
+ params = gitCommandLine
+ [ Param "check-attr"
+ , Param attr
+ , Params "-z --stdin"
+ ] repo
+ topair l = (file, value)
+ where
+ file = Git.Filename.decode $ join sep $ take end bits
+ value = bits !! end
+ end = length bits - 1
+ bits = split sep l
+ sep = ": " ++ attr ++ ": "