module Storage.Hashed
(
readPlainTree, readDarcsHashed
, readBlob
, writePlainTree, writeDarcsHashed
, printPath ) where
import Storage.Hashed.Path
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BL
import Storage.Hashed.Tree ( Tree, TreeItem(..), listImmediate, find, readBlob )
import Storage.Hashed.Darcs( readDarcsHashed, writeDarcsHashed )
import Storage.Hashed.Plain( readPlainTree, writePlainTree )
printPath :: Tree IO -> FilePath -> IO ()
printPath t p = case parsePath p of
Nothing -> putStrLn $ "ERROR: Bad path " ++ p
Just p' -> print' $ find t p'
where print' Nothing = putStrLn $ "ERROR: No object at " ++ p
print' (Just (File b)) = do
putStrLn $ "== Contents of file " ++ p ++ ":"
BL.unpack `fmap` readBlob b >>= putStr
print' (Just (SubTree t')) = do
putStrLn $ "== Listing Tree " ++ p ++ " (immediates only):"
putStr $ unlines $ map BS.unpack $ listNames t'
print' (Just (Stub _ _)) =
putStrLn $ "== (not listing stub at " ++ p ++ ")"
listNames t' = [ n | (n, _) <- listImmediate t' ]