← Back to team overview

dulwich-users team mailing list archive

[PATCH 18/33] Move PackStreamReader from server to pack.

 

From: Dave Borowitz <dborowitz@xxxxxxxxxx>

This will prevent a circular import in the next commit.

Change-Id: I4512d45b22461d8b4ed6fe35a1bc2577f67f8819
---
 NEWS              |    2 ++
 dulwich/pack.py   |   42 ++++++++++++++++++++++++++++++++++++++++++
 dulwich/server.py |   44 +-------------------------------------------
 3 files changed, 45 insertions(+), 43 deletions(-)

diff --git a/NEWS b/NEWS
index 773fe74..4c3bc2b 100644
--- a/NEWS
+++ b/NEWS
@@ -46,6 +46,8 @@
 
   * Include offset in PackStreamReader results. (Dave Borowitz)
 
+  * Move PackStreamReader from server to pack. (Dave Borowitz)
+
  TEST CHANGES
 
   * If setuptools is installed, "python setup.py test" will now run the testsuite.
diff --git a/dulwich/pack.py b/dulwich/pack.py
index 8eca593..638ea55 100644
--- a/dulwich/pack.py
+++ b/dulwich/pack.py
@@ -743,6 +743,48 @@ class PackStreamReader(object):
             raise ChecksumMismatch(sha_to_hex(pack_sha), self.sha.hexdigest())
 
 
+class PackStreamCopier(PackStreamReader):
+    """Class to verify a pack stream as it is being read.
+
+    The pack is read from a ReceivableProtocol using read() or recv() as
+    appropriate and written out to the given file-like object.
+    """
+
+    def __init__(self, read_all, read_some, outfile, delta_iter=None):
+        """Initialize the copier.
+
+        :param read_all: Read function that blocks until the number of requested
+            bytes are read.
+        :param read_some: Read function that returns at least one byte, but may
+            not return the number of bytes requested.
+        :param outfile: File-like object to write output through.
+        :param delta_iter: Optional DeltaChainIterator to record deltas as we
+            read them.
+        """
+        super(PackStreamCopier, self).__init__(read_all, read_some=read_some)
+        self.outfile = outfile
+        self._delta_iter = delta_iter
+
+    def _read(self, read, size):
+        """Read data from the read callback and write it to the file."""
+        data = super(PackStreamCopier, self)._read(read, size)
+        self.outfile.write(data)
+        return data
+
+    def verify(self):
+        """Verify a pack stream and write it to the output file.
+
+        See PackStreamReader.iterobjects for a list of exceptions this may
+        throw.
+        """
+        if self._delta_iter:
+            for offset, type_num, uncomp, _, _ in self.read_objects():
+                self._delta_iter.record(offset, type_num, uncomp)
+        else:
+            for _ in self.read_objects():
+                pass
+
+
 def obj_sha(type, chunks):
     """Compute the SHA for a numeric type and object chunks."""
     sha = make_sha()
diff --git a/dulwich/server.py b/dulwich/server.py
index 269b566..668a817 100644
--- a/dulwich/server.py
+++ b/dulwich/server.py
@@ -44,7 +44,7 @@ from dulwich.objects import (
     hex_to_sha,
     )
 from dulwich.pack import (
-    PackStreamReader,
+    PackStreamCopier,
     write_pack_objects,
     )
 from dulwich.protocol import (
@@ -118,48 +118,6 @@ class BackendRepo(object):
         raise NotImplementedError
 
 
-class PackStreamCopier(PackStreamReader):
-    """Class to verify a pack stream as it is being read.
-
-    The pack is read from a ReceivableProtocol using read() or recv() as
-    appropriate and written out to the given file-like object.
-    """
-
-    def __init__(self, read_all, read_some, outfile, delta_iter=None):
-        """Initialize the copier.
-
-        :param read_all: Read function that blocks until the number of requested
-            bytes are read.
-        :param read_some: Read function that returns at least one byte, but may
-            not return the number of bytes requested.
-        :param outfile: File-like object to write output through.
-        :param delta_iter: Optional DeltaChainIterator to record deltas as we
-            read them.
-        """
-        super(PackStreamCopier, self).__init__(read_all, read_some=read_some)
-        self.outfile = outfile
-        self._delta_iter = delta_iter
-
-    def _read(self, read, size):
-        """Read data from the read callback and write it to the file."""
-        data = super(PackStreamCopier, self)._read(read, size)
-        self.outfile.write(data)
-        return data
-
-    def verify(self):
-        """Verify a pack stream and write it to the output file.
-
-        See PackStreamReader.iterobjects for a list of exceptions this may
-        throw.
-        """
-        if self._delta_iter:
-            for offset, type_num, uncomp, _, _ in self.read_objects():
-                self._delta_iter.record(offset, type_num, uncomp)
-        else:
-            for _ in self.read_objects():
-                pass
-
-
 class DictBackend(Backend):
     """Trivial backend that looks up Git repositories in a dictionary."""
 
-- 
1.7.3.1



References