1 module Storage.Hashed 2 ( -- * Obtaining Trees. 3 -- 4 -- | Please note that Trees obtained this way will contain Stub 5 -- items. These need to be executed (they are IO actions) in order to be 6 -- accessed. Use 'expand' to do this. However, many operations are 7 -- perfectly fine to be used on a stubbed Tree (and it is often more 8 -- efficient to do everything that can be done before expanding a Tree). 9 readPlainTree, readDarcsHashed 10 11 -- * Blob access. 12 , readBlob 13 14 -- * Writing trees. 15 , writePlainTree, writeDarcsHashed 16 17 -- * Unsafe functions for the curious explorer. 18 -- 19 -- | These are more useful for playing within ghci than for real, serious 20 -- programs. They generally trade safety for conciseness. Please use 21 -- responsibly. Don't kill innocent kittens. 22 , printPath ) where 23 24 import Storage.Hashed.Path 25 import qualified Data.ByteString.Char8 as BS 26 import qualified Data.ByteString.Lazy.Char8 as BL 27 import Storage.Hashed.Tree ( Tree, TreeItem(..), listImmediate, find, readBlob ) 28 29 -- For re-exports. 30 import Storage.Hashed.Darcs( readDarcsHashed, writeDarcsHashed ) 31 import Storage.Hashed.Plain( readPlainTree, writePlainTree ) 32 33 ------------------------ 34 -- For explorers 35 -- 36 37 -- | Take a relative FilePath within a Tree and print the contents of the 38 -- object there. Useful for exploration, less so for serious programming. 39 printPath :: Tree IO -> FilePath -> IO () 40 printPath t p = print' $ find t (unsafePathFromString p) 41 where print' Nothing = putStrLn $ "ERROR: No object at " ++ p 42 print' (Just (File b)) = do 43 putStrLn $ "== Contents of file " ++ p ++ ":" 44 BL.unpack `fmap` readBlob b >>= putStr 45 print' (Just (SubTree t')) = do 46 putStrLn $ "== Listing Tree " ++ p ++ " (immediates only):" 47 putStr $ unlines $ map BS.unpack $ listNames t' 48 print' (Just (Stub _ _)) = 49 putStrLn $ "== (not listing stub at " ++ p ++ ")" 50 listNames t' = [ n | (n, _) <- listImmediate t' ] 51