From 7c1169f6ea406fec1e26e99821e18e66437e65eb Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 5 Jun 2010 00:20:01 +0200 Subject: Removed compression flag from IStream and OStream types, as a valid object will always be compressed if generated by the system ( even future memory db's will compress it ) loose db: implemented direct stream copy, indicated by a sha set in the IStream, including test. This will be the case once Packs are exploded for instance --- lib/git/odb/db.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib/git/odb/db.py') diff --git a/lib/git/odb/db.py b/lib/git/odb/db.py index a8de28ec..d970b0bf 100644 --- a/lib/git/odb/db.py +++ b/lib/git/odb/db.py @@ -29,7 +29,8 @@ from utils import ( from fun import ( chunk_size, loose_object_header_info, - write_object + write_object, + stream_copy ) import tempfile @@ -262,7 +263,6 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW): def store(self, istream): """note: The sha we produce will be hex by nature""" - assert istream.sha is None, "Direct istream writing not yet implemented" tmp_path = None writer = self.ostream() if writer is None: @@ -273,8 +273,13 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW): try: try: - write_object(istream.type, istream.size, istream.read, writer.write, - chunk_size=self.stream_chunk_size) + if istream.sha is not None: + stream_copy(istream.read, writer.write, istream.size, self.stream_chunk_size) + else: + # write object with header, we have to make a new one + write_object(istream.type, istream.size, istream.read, writer.write, + chunk_size=self.stream_chunk_size) + # END handle direct stream copies except: if tmp_path: os.remove(tmp_path) @@ -285,7 +290,7 @@ class LooseObjectDB(FileDBBase, ObjectDBR, ObjectDBW): writer.close() # END assure target stream is closed - sha = writer.sha(as_hex=True) + sha = istream.sha or writer.sha(as_hex=True) if tmp_path: obj_path = self.db_path(self.object_path(sha)) -- cgit v1.2.1