1{-# OPTIONS_GHC -Wall #-}
14import Prelude hiding (appendFile)
15import Control.Monad (foldM)
16import qualified Control.Monad.State as State
17import qualified Data.Binary.Get as Binary
18import qualified Data.ByteString as BS
19import qualified Data.ByteString.Builder as BS
20import qualified Data.ByteString.Builder.Extra as BS (defaultChunkSize)
21import qualified Data.ByteString.Lazy as LBS
22import qualified Data.Digest.Pure.SHA as SHA
23import qualified System.IO as IO
30type Hasher = State.StateT State IO ()
33type Digest = SHA.Digest SHA.SHA1State
36put :: FilePath -> Hasher -> IO Digest
38 IO.withBinaryFile path IO.WriteMode $ \handle ->
39 do let state = State handle 0 SHA.sha1Incremental
40 (State _ len decoder) <- State.execStateT hasher state
41 return (SHA.completeSha1Incremental decoder len)
44toString :: Digest -> String
55 { _handle :: !IO.Handle
57 , _decoder :: !(Binary.Decoder SHA.SHA1State)
65putByteString :: BS.ByteString -> Hasher
68 State.put =<< State.liftIO (appendByteString state chunk)
71putBuilder :: BS.Builder -> Hasher
74 State.put =<< State.liftIO (appendBuilder builder state)
77putFile :: FilePath -> Hasher
80 State.put =<< State.liftIO (appendFile path state)
87appendByteString :: State -> BS.ByteString -> IO State
88appendByteString (State handle len decoder) chunk =
89 do BS.hPut handle chunk
90 return $ State handle (len + BS.length chunk) (Binary.pushChunk decoder chunk)
93appendBuilder :: BS.Builder -> State -> IO State
94appendBuilder builder state =
95 foldM appendByteString state $
96 LBS.toChunks (BS.toLazyByteString builder)
99appendFile :: FilePath -> State -> IO State
100appendFile path state =
101 IO.withBinaryFile path IO.ReadMode $ \handle ->
102 appendHelp handle state
105appendHelp :: IO.Handle -> State -> IO State
106appendHelp handle state =
107 do chunk <- BS.hGet handle BS.defaultChunkSize
110 else appendHelp handle =<< appendByteString state chunk
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list