module Storage.Hashed
(
readPlainTree, readDarcsHashed
, readBlob
, writePlainTree, writeDarcsHashed
, floatPath, printPath ) where
import Storage.Hashed.AnchoredPath
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 = print' $ find t (floatPath 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 | (Name n, _) <- listImmediate t' ]