summaryrefslogtreecommitdiff
path: root/lib/git/odb/db.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-06-05 00:20:01 +0200
committerSebastian Thiel <byronimo@gmail.com>2010-06-05 00:20:01 +0200
commit7c1169f6ea406fec1e26e99821e18e66437e65eb (patch)
treec6743920ae8d36c67b8401403ef8d682e12c794d /lib/git/odb/db.py
parenta243827ab3346e188e99db2f9fc1f916941c9b1a (diff)
downloadgitpython-7c1169f6ea406fec1e26e99821e18e66437e65eb.tar.gz
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
Diffstat (limited to 'lib/git/odb/db.py')
-rw-r--r--lib/git/odb/db.py15
1 files changed, 10 insertions, 5 deletions
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))