Commits

Stefan Saasen committed e85edda

Minor code and doc cleanup

Comments (0)

Files changed (5)

src/Git/Common.hs

 -- | Create a packet line prefixed with the overall length. Length is 4 byte,
 -- hexadecimal, padded with 0.
 pktLine :: String -> String 
-pktLine msg = printf "%04s%s" (toHex . (4 +) $ length msg) msg
+pktLine = printf "%04s%s" =<< toHex . (4 +) . length
 
 -- | Return the Git flush packet.
 flushPkt :: String

src/Git/Remote/Operations.hs

 lsRemote' :: Remote -> IO [PacketLine]
 lsRemote' Remote{..} = withSocketsDo $
     withConnection getHost (show $ fromMaybe 9418 getPort) $ \sock -> do
-        let payload = refDiscovery getHost getRepository
+        let payload = gitProtoRequest getHost getRepository
         send sock payload
         response <- receive sock
         send sock flushPkt -- Tell the server to disconnect
         return $ parsePacket $ L.fromChunks [response]
 
-refDiscovery :: String -> String -> String
-refDiscovery host repo = pktLine $ "git-upload-pack /" ++ repo ++ "\0host="++host++"\0"
+gitProtoRequest :: String -> String -> String
+gitProtoRequest host repo = pktLine $ "git-upload-pack /" ++ repo ++ "\0host="++host++"\0"
 
 repositoryName :: Remote -> String
 repositoryName = takeFileName . dropExtension . getRepository
 receivePack :: Remote -> IO ([Ref], B.ByteString)
 receivePack Remote{..} = withSocketsDo $
     withConnection getHost (show $ fromMaybe 9418 getPort) $ \sock -> do
-        let payload = refDiscovery getHost getRepository
+        let payload = gitProtoRequest getHost getRepository
         send sock payload
         response <- receive sock
         let pack    = parsePacket $ L.fromChunks [response]

src/Git/Remote/TcpClient.hs

 receiveFully sock = receive' sock mempty
    where receive' s acc = do
             msg <- recv s 4096
-            if C.null msg then return acc else receive' s $ mappend acc msg
+            if C.null msg then return acc else receive' s $ acc `mappend` msg
 
 
 -- see sideband.c
         connect sock (addrAddress serveraddr)
         return sock
 
--- | Read a packet line
+-- | Read a git packet line (variable length binary string prefixed with the overall length). 
+-- Length is 4 byte, hexadecimal, padded with 0.
 readPacketLine :: Socket -> IO (Maybe C.ByteString)
 readPacketLine sock = do
-        msg <- loop C.empty 4 -- check for a zero length return -> disconnected
-        if C.null msg then return Nothing else
-            case readHex $ C.unpack msg of
+        len <- readFully mempty 4 -- check for a zero length return -> disconnected
+        if C.null len then return Nothing else
+            case readHex $ C.unpack len of
                 ((l,_):_) | l > 4 -> do
-                     line <- loop C.empty (l-4)
+                     line <- readFully mempty (l-4)
                      return $ Just line
                 _ -> return Nothing
-    where loop acc expected = do
+    where readFully acc expected = do
             line <- recv sock expected
             let len  = C.length line
-                acc' = acc `C.append` line
+                acc' = acc `mappend` line
                 cont = len /= expected && not (C.null line)
-            if cont then loop acc' (expected - len) else return acc'
+            if cont then readFully acc' (expected - len) else return acc'
 
 {-
 If 'side-band' or 'side-band-64k' capabilities have been specified by

src/Git/Repository.hs

 import Numeric                                              (readOct)
 
 -- | Updates files in the working tree to match the given <tree-ish>
-
 checkoutHead :: WithRepository ()
 checkoutHead = do
     repo <- ask

src/Git/Store/ObjectStore.hs

         bs <- C.readFile filename
         return $ parseBlob sha $ inflate bs
     else return Nothing
-    where inflate blob = B.concat $ L.toChunks $ Z.decompress $ L.fromChunks [blob]
+    where inflate blob = B.concat . L.toChunks . Z.decompress $ L.fromChunks [blob]
 
 -- header: "type size\0"
 -- sha1 $ header ++ content
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.