smudge filter working
authorJoey Hess <joeyh@joeyh.name>
Fri, 4 Dec 2015 18:03:10 +0000 (14:03 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 4 Dec 2015 18:03:10 +0000 (14:03 -0400)
Command/Smudge.hs

index 22f9efd696136eedc084e46b3df718946fd7a80b..dc618d36e07fa16e22a494692832f1ab1443a806 100644 (file)
@@ -9,9 +9,9 @@ module Command.Smudge where
 
 import Common.Annex
 import Command
-import Annex.Content
-import Annex.Link
-import Git.Types
+import Types.Key
+
+import qualified Data.ByteString.Lazy as B
 
 cmd :: Command
 cmd = dontCheck repoExists $
@@ -23,7 +23,25 @@ seek :: CmdParams -> CommandSeek
 seek = withWords start
 
 start :: [String] -> CommandStart
-start [file] = do
-       error ("smudge " ++ file)
+start [_file] = do
+       liftIO $ fileEncoding stdin
+       s <- liftIO $ hGetContents stdin
+       case parsePointer s of
+               Nothing -> liftIO $ putStr s
+               Just k -> do
+                       content <- calcRepo (gitAnnexLocation k)
+                       liftIO $ maybe
+                               (putStr s)
+                               (B.hPut stdout)
+                               =<< catchMaybeIO (B.readFile content)
+       stop
 start [] = error "smudge filter run without filename; upgrade git"
 start _ = error "smudge filter passed multiple filenames"
+
+parsePointer :: String -> Maybe Key
+parsePointer s
+       | length s' >= maxsz = Nothing -- too long to be a key pointer
+       | otherwise = headMaybe (lines s') >>= file2key
+  where
+       s' = take maxsz s
+       maxsz = 81920