summaryrefslogtreecommitdiff
path: root/lib/git
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
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')
-rw-r--r--lib/git/odb/db.py15
-rw-r--r--lib/git/odb/stream.py29
2 files changed, 17 insertions, 27 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))
diff --git a/lib/git/odb/stream.py b/lib/git/odb/stream.py
index 654bcbf6..da97cf5b 100644
--- a/lib/git/odb/stream.py
+++ b/lib/git/odb/stream.py
@@ -69,15 +69,6 @@ class OStream(OInfo):
def __init__(self, *args, **kwargs):
tuple.__init__(self)
- #{ Interface
-
- def is_compressed(self):
- """:return: True if reads of this stream yield zlib compressed data. Default False
- :note: this does not imply anything about the actual internal storage.
- Hence the data could be uncompressed, but read compressed, or vice versa"""
- return False
-
- #} END interface
#{ Stream Reader Interface
@@ -97,11 +88,11 @@ class IStream(list):
The only method your content stream must support is 'read'"""
__slots__ = tuple()
- def __new__(cls, type, size, stream, sha=None, compressed=False):
- return list.__new__(cls, (sha, type, size, stream, compressed, None))
+ def __new__(cls, type, size, stream, sha=None):
+ return list.__new__(cls, (sha, type, size, stream, None))
- def __init__(self, type, size, stream, sha=None, compressed=None):
- list.__init__(self, (sha, type, size, stream, compressed, None))
+ def __init__(self, type, size, stream, sha=None):
+ list.__init__(self, (sha, type, size, stream, None))
#{ Interface
@@ -117,11 +108,11 @@ class IStream(list):
def _error(self):
""":return: the error that occurred when processing the stream, or None"""
- return self[5]
+ return self[4]
def _set_error(self, exc):
"""Set this input stream to the given exc, may be None to reset the error"""
- self[5] = exc
+ self[4] = exc
error = property(_error, _set_error)
@@ -172,13 +163,6 @@ class IStream(list):
stream = property(_stream, _set_stream)
#} END odb info interface
-
- #{ OStream interface
-
- def is_compressed(self):
- return self[4]
-
- #} END OStream interface
class InvalidOInfo(tuple):
@@ -397,6 +381,7 @@ class DecompressMemMapReader(object):
class Sha1Writer(object):
"""Simple stream writer which produces a sha whenever you like as it degests
everything it is supposed to write"""
+ __slots__ = "sha1"
def __init__(self):
self.sha1 = make_sha("")