client: don't assume server response is of length 20 rc-fix-pack-protocol-v2
authorTay Ray Chuan <rctay89@gmail.com>
Sun, 4 Apr 2010 14:58:31 +0000 (22:58 +0800)
committerTay Ray Chuan <rctay89@gmail.com>
Sat, 10 Apr 2010 03:49:35 +0000 (11:49 +0800)
We do not for sure the length; it is safer to use
Protocol.read_pkt_line().

Also, handle HangupException if read_pkt_line() raises it. This happens
when talking to old versions of git-daemon (v1.6.6.1-26-g38a81b4), where
there won't be anything to read.

dulwich/client.py

index a91d7994bef173edad339e3834f2ac62353b3868..579c708cfc2caf3202ce061fbce075ba9b825952 100644 (file)
@@ -28,6 +28,7 @@ import subprocess
 
 from dulwich.errors import (
     ChecksumMismatch,
+    HangupException,
     )
 from dulwich.protocol import (
     Protocol,
@@ -119,10 +120,15 @@ class GitClient(object):
                                          len(objects))
         
         # read the final confirmation sha
-        client_sha = self.proto.read(20)
-        if not client_sha in (None, "", sha):
-            raise ChecksumMismatch(sha, client_sha)
-            
+        try:
+            client_sha = self.proto.read_pkt_line()
+            if not client_sha in (None, "", sha):
+                raise ChecksumMismatch(sha, client_sha)
+        except HangupException:
+            # for git-daemon versions before v1.6.6.1-26-g38a81b4, there is
+            # nothing to read; catch this and hide from the user.
+            pass
+
         return new_refs
 
     def fetch(self, path, target, determine_wants=None, progress=None):