diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-12-04 14:03:10 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-12-04 14:03:10 -0400 |
commit | 563e5613f28710d2e2dd56b0f06ef2714e9a14d2 (patch) | |
tree | 7aba444f95b4e377d978a409d65a99363ba738f9 /Command/Smudge.hs | |
parent | e364396efca11355befa2d0f3e6eb89304c3dac7 (diff) |
smudge filter working
Diffstat (limited to 'Command/Smudge.hs')
-rw-r--r-- | Command/Smudge.hs | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/Command/Smudge.hs b/Command/Smudge.hs index 22f9efd69..dc618d36e 100644 --- a/Command/Smudge.hs +++ b/Command/Smudge.hs @@ -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 |