From 282018b79cc8df078381097cb3aeb29ff56e83c6 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 2 Jun 2010 20:11:00 +0200 Subject: Added first design and frame for object database. In a first step, loose objects will be written using our utilities, and certain object retrieval functionality moves into the GitObjectDatabase which is used by the repo instance Added performance test for object database access, which shows quite respectable tree parsing performance, and okay blob access. Nonetheless, it will be hard to beat the c performance using a pure python implementation, but it can be a nice practice to write it anyway to allow more direct pack manipulations. Some could benefit from the ability to write packs as these can serve as local cache if alternates are used --- test/git/test_odb.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/git/test_odb.py (limited to 'test/git/test_odb.py') diff --git a/test/git/test_odb.py b/test/git/test_odb.py new file mode 100644 index 00000000..6f92a5c1 --- /dev/null +++ b/test/git/test_odb.py @@ -0,0 +1,12 @@ +"""Test for object db""" + +from test.testlib import * +from git.odb.db import * + + +class TestDB(TestBase): + """Test the different db class implementations""" + + def test_loose_db(self): + self.fail("todo") + -- cgit v1.2.1 From 8b86f9b399a8f5af792a04025fdeefc02883f3e5 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 2 Jun 2010 22:40:52 +0200 Subject: initial version of loose object writing and simple cached object lookup appears to be working --- test/git/test_odb.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'test/git/test_odb.py') diff --git a/test/git/test_odb.py b/test/git/test_odb.py index 6f92a5c1..bc92a493 100644 --- a/test/git/test_odb.py +++ b/test/git/test_odb.py @@ -2,11 +2,38 @@ from test.testlib import * from git.odb.db import * +from git import Blob + +from cStringIO import StringIO +import os class TestDB(TestBase): """Test the different db class implementations""" - def test_loose_db(self): - self.fail("todo") + # data + two_lines = "1234\nhello world" + + all_data = (two_lines, ) + + def _assert_object_writing(self, db): + """General tests to verify object writing, compatible to iObjectDBW + :note: requires write access to the database""" + # start in dry-run mode + for dry_run in range(1, -1, -1): + for data in self.all_data: + for hex_sha in range(2): + sha = db.to_object(Blob.type, len(data), StringIO(data), dry_run, hex_sha) + assert db.has_object(sha) != dry_run + assert len(sha) == 20 + hex_sha * 20 + # END for each sha type + # END for each data set + # END for each dry_run mode + + @with_bare_rw_repo + def test_writing(self, rwrepo): + ldb = LooseObjectDB(os.path.join(rwrepo.git_dir, 'objects')) + + # write data + self._assert_object_writing(ldb) -- cgit v1.2.1 From 6f8ce8901e21587cd2320562df412e05b5ab1731 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 2 Jun 2010 23:53:29 +0200 Subject: added frame for object reading, including simple test --- test/git/test_odb.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/git/test_odb.py') diff --git a/test/git/test_odb.py b/test/git/test_odb.py index bc92a493..b2840719 100644 --- a/test/git/test_odb.py +++ b/test/git/test_odb.py @@ -3,6 +3,7 @@ from test.testlib import * from git.odb.db import * from git import Blob +from git.errors import BadObject from cStringIO import StringIO import os @@ -26,6 +27,18 @@ class TestDB(TestBase): sha = db.to_object(Blob.type, len(data), StringIO(data), dry_run, hex_sha) assert db.has_object(sha) != dry_run assert len(sha) == 20 + hex_sha * 20 + + # verify data - the slow way, we want to run code + if not dry_run: + type, size = db.object_info(sha) + assert Blob.type == type + assert size == len(data) + + type, size, stream = db.object(sha) + assert stream.read() == data + else: + self.failUnlessRaises(BadObject, db.object_info, sha) + self.failUnlessRaises(BadObject, db.object, sha) # END for each sha type # END for each data set # END for each dry_run mode -- cgit v1.2.1 From a1e80445ad5cb6da4c0070d7cb8af89da3b0803b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 4 Jun 2010 14:41:15 +0200 Subject: initial version of new odb design to facilitate a channel based multi-threading implementation of all odb functions --- test/git/test_odb.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/git/test_odb.py') diff --git a/test/git/test_odb.py b/test/git/test_odb.py index b2840719..80597df6 100644 --- a/test/git/test_odb.py +++ b/test/git/test_odb.py @@ -18,26 +18,26 @@ class TestDB(TestBase): all_data = (two_lines, ) def _assert_object_writing(self, db): - """General tests to verify object writing, compatible to iObjectDBW + """General tests to verify object writing, compatible to ObjectDBW :note: requires write access to the database""" # start in dry-run mode for dry_run in range(1, -1, -1): for data in self.all_data: for hex_sha in range(2): - sha = db.to_object(Blob.type, len(data), StringIO(data), dry_run, hex_sha) + sha = db.store(Blob.type, len(data), StringIO(data), dry_run, hex_sha) assert db.has_object(sha) != dry_run assert len(sha) == 20 + hex_sha * 20 # verify data - the slow way, we want to run code if not dry_run: - type, size = db.object_info(sha) + type, size = db.info(sha) assert Blob.type == type assert size == len(data) - type, size, stream = db.object(sha) + type, size, stream = dbstreamsha) assert stream.read() == data else: - self.failUnlessRaises(BadObject, db.object_info, sha) + self.failUnlessRaises(BadObject, db.info, sha) self.failUnlessRaises(BadObject, db.object, sha) # END for each sha type # END for each data set -- cgit v1.2.1 From e746f96bcc29238b79118123028ca170adc4ff0f Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 4 Jun 2010 17:22:08 +0200 Subject: Fixed implementation after design change to deal with it - all tests run, but next there will have to be more through testing --- test/git/test_odb.py | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) (limited to 'test/git/test_odb.py') diff --git a/test/git/test_odb.py b/test/git/test_odb.py index 80597df6..c3a03714 100644 --- a/test/git/test_odb.py +++ b/test/git/test_odb.py @@ -1,7 +1,8 @@ """Test for object db""" from test.testlib import * -from git.odb.db import * +from git.odb import * +from git.odb.stream import Sha1Writer from git import Blob from git.errors import BadObject @@ -20,26 +21,39 @@ class TestDB(TestBase): def _assert_object_writing(self, db): """General tests to verify object writing, compatible to ObjectDBW :note: requires write access to the database""" - # start in dry-run mode - for dry_run in range(1, -1, -1): + # start in 'dry-run' mode, using a simple sha1 writer + ostreams = (Sha1Writer, None) + for ostreamcls in ostreams: for data in self.all_data: - for hex_sha in range(2): - sha = db.store(Blob.type, len(data), StringIO(data), dry_run, hex_sha) - assert db.has_object(sha) != dry_run - assert len(sha) == 20 + hex_sha * 20 + dry_run = ostreamcls is not None + ostream = None + if ostreamcls is not None: + ostream = ostreamcls() + # END create ostream + + prev_ostream = db.set_ostream(ostream) + assert type(prev_ostream) in ostreams or prev_ostream in ostreams + + istream = IStream(Blob.type, len(data), StringIO(data)) + my_istream = db.store(istream) + sha = istream.sha + assert my_istream is istream + assert db.has_object(sha) != dry_run + assert len(sha) == 40 # for now we require 40 byte shas as default + + # verify data - the slow way, we want to run code + if not dry_run: + info = db.info(sha) + assert Blob.type == info.type + assert info.size == len(data) - # verify data - the slow way, we want to run code - if not dry_run: - type, size = db.info(sha) - assert Blob.type == type - assert size == len(data) - - type, size, stream = dbstreamsha) - assert stream.read() == data - else: - self.failUnlessRaises(BadObject, db.info, sha) - self.failUnlessRaises(BadObject, db.object, sha) - # END for each sha type + ostream = db.stream(sha) + assert ostream.read() == data + assert ostream.type == Blob.type + assert ostream.size == len(data) + else: + self.failUnlessRaises(BadObject, db.info, sha) + self.failUnlessRaises(BadObject, db.stream, sha) # END for each data set # END for each dry_run mode -- cgit v1.2.1