diff dulwich/protocol.py @ 87:babc85201dc4

merge of upstream work from dulwich project
author Scott Chacon <schacon@gmail.com>
date Fri, 08 May 2009 16:12:38 -0700
parents f0daee676e10
children
line wrap: on
line diff
--- a/dulwich/protocol.py	Fri May 08 15:06:38 2009 -0700
+++ b/dulwich/protocol.py	Fri May 08 16:12:38 2009 -0700
@@ -79,13 +79,6 @@
             yield pkt
             pkt = self.read_pkt_line()
 
-    def write_file(self, f):
-        try:
-            for line in f:
-                self.write(line)
-        finally:
-            f.close()
-        
     def write_pkt_line(self, line):
         """
         Sends a 'pkt line' to the remote git process
@@ -104,6 +97,25 @@
         except socket.error, e:
             raise GitProtocolError(e)
 
+    def write_file(self):
+        class ProtocolFile(object):
+
+            def __init__(self, proto):
+                self._proto = proto
+                self._offset = 0
+
+            def write(self, data):
+                self._proto.write(data)
+                self._offset += len(data)
+
+            def tell(self):
+                return self._offset
+
+            def close(self):
+                pass
+
+        return ProtocolFile(self)
+
     def write_sideband(self, channel, blob):
         """
         Write data to the sideband (a git multiplexing method)