Commits

Stefan Saasen committed f93d60e

Minor cleanup

Comments (0)

Files changed (1)

src/Git/Pack/Packfile.hs

 
 import Control.Applicative
 import Data.ByteString (ByteString)
-import qualified Data.Iteratee as I
+import qualified Data.Iteratee          as It
 import Data.Iteratee.Binary
 import Data.Iteratee.ZLib
 import Control.Monad                    (replicateM)
 
 -- | Parse the given pack file into a "Packfile" representation
 packRead :: FilePath -> IO Packfile
-packRead = I.fileDriverRandom parsePackFile
+packRead = It.fileDriverRandom parsePackFile
 
 -- ============================================================================== --
 
-parsePackFile :: I.Iteratee ByteString IO Packfile
+parsePackFile :: It.Iteratee ByteString IO Packfile
 parsePackFile = do
     magic       <- endianRead4 MSB -- 4 bytes, big-endian
     version'    <- endianRead4 MSB
                 else return InvalidPackfile
   where packMagic = fromOctets $ map (fromIntegral . ord) "PACK"
 
-parseObjects :: Word32 -> Word32 -> I.Iteratee ByteString IO Packfile
+parseObjects :: Word32 -> Word32 -> It.Iteratee ByteString IO Packfile
 parseObjects version' num = do
     objs <- catMaybes <$> replicateM (fromIntegral num) parsePackObject
     return $ Packfile version' num objs
 
 
-parsePackObject :: I.Iteratee ByteString IO (Maybe PackfileObject)
+parsePackObject :: It.Iteratee ByteString IO (Maybe PackfileObject)
 parsePackObject = do
-    byte <- I.head -- read 1 byte
+    byte <- It.head -- read 1 byte
     let objectType' = byte `shiftR` 4 .&. 7 -- shift right and masking the 4th least significtan bit
         initial     = fromIntegral $ byte .&. 15
     size' <- if isMsbSet byte then parseObjectSize initial 0 else return initial
     obj <- toPackObjectType objectType'
-    !content <- I.joinI $ enumInflate Zlib defaultDecompressParams I.stream2stream
+    !content <- It.joinI $ enumInflate Zlib defaultDecompressParams It.stream2stream
     return $ (\t -> PackfileObject t size' content) <$> obj
 
 -- Parse the variable length size header part of the object entry
-parseObjectSize :: Int -> Int -> I.Iteratee ByteString IO Int
+parseObjectSize :: Int -> Int -> It.Iteratee ByteString IO Int
 parseObjectSize size' iter = do
-    nextByte <- I.head
+    nextByte <- It.head
     let add           = (coerce (nextByte .&. 127) :: Int) `shiftL` (4 + (iter * 7)) -- shift depends on the number of iterations
         acc           = size' + fromIntegral add
     if isMsbSet nextByte then
 -- =================================================================================
 
 -- Map the internal representation of the object type to the PackObjectType
-toPackObjectType :: (Show a, Integral a) => a -> I.Iteratee ByteString IO (Maybe PackObjectType)
+toPackObjectType :: (Show a, Integral a) => a -> It.Iteratee ByteString IO (Maybe PackObjectType)
 toPackObjectType 1  = return $ Just OBJ_COMMIT
 toPackObjectType 2  = return $ Just OBJ_TREE
 toPackObjectType 3  = return $ Just OBJ_BLOB
     offset <- readOffset 0 0
     return $ Just (OBJ_OFS_DELTA offset)
 toPackObjectType 7  = do 
-    baseObj <- replicateM 20 I.head -- 20-byte base object name SHA1
+    baseObj <- replicateM 20 It.head -- 20-byte base object name SHA1
     return $ Just (OBJ_REF_DELTA baseObj)
 toPackObjectType _  = return Nothing
 
 --  concatenating the lower 7 bit of each byte, and
 --  for n >= 2 adding 2^7 + 2^14 + ... + 2^(7*(n-1))
 --  to the result.
-readOffset :: Int -> Int -> I.Iteratee ByteString IO Int
+readOffset :: Int -> Int -> It.Iteratee ByteString IO Int
 readOffset shft acc = do
-    x <- I.head
+    x <- It.head
     let bs = acc + ((coerce (x .&. 0x7f) :: Int) `shiftL` shft)
     if isMsbSet x
         then readOffset (shft+7) (bs+1)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.