From 6e5aae2fc8c3832bdae1cd5e0a269405fb059231 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 23 Nov 2010 12:35:34 +0100 Subject: Initial interface including some of the implementation of the RefLog. TestCase scetched out for now tests: Added tests to verify that objects don't have a dict. Previously, due to a missing __slots__ member in Serializable, most objects would indeed have a dict, although the opposite was intended --- test/test_reflog.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/test_reflog.py (limited to 'test/test_reflog.py') diff --git a/test/test_reflog.py b/test/test_reflog.py new file mode 100644 index 00000000..efcc7f33 --- /dev/null +++ b/test/test_reflog.py @@ -0,0 +1,32 @@ +from git.test.lib import * +from git.objects import IndexObject, Actor +from git.refs import * + +class TestRefLog(TestBase): + + def test_reflogentry(self): + nullhexsha = IndexObject.NULL_HEX_SHA + hexsha = 'F' * 40 + actor = Actor('name', 'email') + msg = "message" + + self.failUnlessRaises(ValueError, RefLogEntry.new, nullhexsha, hexsha, 'noactor', 0, 0, "") + e = RefLogEntry.new(nullhexsha, hexsha, actor, 0, 1, msg) + + assert e.oldhexsha == nullhexsha + assert e.newhexsha == hexsha + assert e.actor == actor + assert e.time[0] == 0 + assert e.time[1] == 1 + assert e.message == msg + + # check representation (roughly) + assert repr(e).startswith(nullhexsha) + + def test_base(self): + pass + # raise on invalid revlog + # TODO: Try multiple corrupted ones ! + + + # test serialize and deserialize - results must match exactly -- cgit v1.2.3 From a93eb7e8484e5bb40f9b8d11ac64a1621cf4c9cd Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 23 Nov 2010 15:49:29 +0100 Subject: Implemented reflog reading and writing --- test/test_reflog.py | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'test/test_reflog.py') diff --git a/test/test_reflog.py b/test/test_reflog.py index efcc7f33..a017106e 100644 --- a/test/test_reflog.py +++ b/test/test_reflog.py @@ -2,6 +2,10 @@ from git.test.lib import * from git.objects import IndexObject, Actor from git.refs import * +import tempfile +import shutil +import os + class TestRefLog(TestBase): def test_reflogentry(self): @@ -24,9 +28,47 @@ class TestRefLog(TestBase): assert repr(e).startswith(nullhexsha) def test_base(self): - pass + rlp_head = fixture_path('reflog_HEAD') + rlp_master = fixture_path('reflog_master') + tdir = tempfile.mktemp(suffix="test_reflogs") + os.mkdir(tdir) + + # verify we have a ref - with the creation of a new ref, the reflog + # will be created as well + rlp_master_ro = RefLog.path(self.rorepo.heads.master) + assert os.path.isfile(rlp_master_ro) + + # simple read + reflog = RefLog.from_file(rlp_master_ro) + assert isinstance(reflog, RefLog) + assert len(reflog) + + # iter_entries works with path and with stream + assert len(list(RefLog.iter_entries(open(rlp_master)))) + assert len(list(RefLog.iter_entries(rlp_master))) + # raise on invalid revlog # TODO: Try multiple corrupted ones ! - + pp = 'reflog_invalid_' + for suffix in ('oldsha', 'newsha', 'email', 'date', 'sep'): + self.failUnlessRaises(ValueError, RefLog.from_file, fixture_path(pp+suffix)) + #END for each invalid file + # test serialize and deserialize - results must match exactly + for rlp in (rlp_head, rlp_master): + reflog = RefLog.from_file(rlp) + tfile = os.path.join(tdir, os.path.basename(rlp)) + reflog.to_file(tfile) + + # parsed result must match ... + treflog = RefLog.from_file(tfile) + assert treflog == reflog + + # ... as well as each bytes of the written stream + assert open(tfile).read() == open(rlp).read() + # END for each reflog + + + # finally remove our temporary data + shutil.rmtree(tdir) -- cgit v1.2.3 From a21a9f6f13861ddc65671b278e93cf0984adaa30 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 23 Nov 2010 21:14:59 +0100 Subject: Actor: Moved it from git.objects.util to git.util, adjusted all imports accordingly. Added methods to Actor to retrieve the global committer and author information Reflog: implemented and tested append_entry method --- test/test_reflog.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'test/test_reflog.py') diff --git a/test/test_reflog.py b/test/test_reflog.py index a017106e..67b1a9da 100644 --- a/test/test_reflog.py +++ b/test/test_reflog.py @@ -1,6 +1,7 @@ from git.test.lib import * -from git.objects import IndexObject, Actor +from git.objects import IndexObject from git.refs import * +from git.util import Actor import tempfile import shutil @@ -40,6 +41,7 @@ class TestRefLog(TestBase): # simple read reflog = RefLog.from_file(rlp_master_ro) + assert reflog._path is not None assert isinstance(reflog, RefLog) assert len(reflog) @@ -56,6 +58,8 @@ class TestRefLog(TestBase): # test serialize and deserialize - results must match exactly + binsha = chr(255)*20 + msg = "my reflog message" for rlp in (rlp_head, rlp_master): reflog = RefLog.from_file(rlp) tfile = os.path.join(tdir, os.path.basename(rlp)) @@ -67,6 +71,18 @@ class TestRefLog(TestBase): # ... as well as each bytes of the written stream assert open(tfile).read() == open(rlp).read() + + # append an entry - it gets written automatically + entry = treflog.append_entry(IndexObject.NULL_BIN_SHA, binsha, msg) + assert entry.oldhexsha == IndexObject.NULL_HEX_SHA + assert entry.newhexsha == 'f'*40 + assert entry.message == msg + assert treflog == RefLog.from_file(tfile) + + # but not this time + treflog.append_entry(binsha, binsha, msg, write=False) + assert treflog != RefLog.from_file(tfile) + # END for each reflog -- cgit v1.2.3 From 7029773512eee5a0bb765b82cfdd90fd5ab34e15 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 23 Nov 2010 23:20:11 +0100 Subject: Implemented revlog.append_entry as classmethod, to assure we will always actually write_append the new entry, instead of rewriting the whole file. Added file-locking and directory handling, so the implementation should be similar (enough) to the git reference implementation. Next up is to implement a way to update the reflog when changing references, which is going to be a little more complicated --- test/test_reflog.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'test/test_reflog.py') diff --git a/test/test_reflog.py b/test/test_reflog.py index 67b1a9da..e99e5ba5 100644 --- a/test/test_reflog.py +++ b/test/test_reflog.py @@ -72,17 +72,12 @@ class TestRefLog(TestBase): # ... as well as each bytes of the written stream assert open(tfile).read() == open(rlp).read() - # append an entry - it gets written automatically - entry = treflog.append_entry(IndexObject.NULL_BIN_SHA, binsha, msg) + # append an entry + entry = RefLog.append_entry(tfile, IndexObject.NULL_BIN_SHA, binsha, msg) assert entry.oldhexsha == IndexObject.NULL_HEX_SHA assert entry.newhexsha == 'f'*40 assert entry.message == msg - assert treflog == RefLog.from_file(tfile) - - # but not this time - treflog.append_entry(binsha, binsha, msg, write=False) - assert treflog != RefLog.from_file(tfile) - + assert RefLog.from_file(tfile)[-1] == entry # END for each reflog -- cgit v1.2.3 From ec0657cf5de9aeb5629cc4f4f38b36f48490493e Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 24 Nov 2010 15:56:49 +0100 Subject: Unified object and commit handling which should make the reflog handling much easier. There is some bug in it though, it still needs fixing --- test/test_reflog.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/test_reflog.py') diff --git a/test/test_reflog.py b/test/test_reflog.py index e99e5ba5..0c8e538b 100644 --- a/test/test_reflog.py +++ b/test/test_reflog.py @@ -60,6 +60,7 @@ class TestRefLog(TestBase): # test serialize and deserialize - results must match exactly binsha = chr(255)*20 msg = "my reflog message" + cr = repo.config_reader() for rlp in (rlp_head, rlp_master): reflog = RefLog.from_file(rlp) tfile = os.path.join(tdir, os.path.basename(rlp)) @@ -73,7 +74,7 @@ class TestRefLog(TestBase): assert open(tfile).read() == open(rlp).read() # append an entry - entry = RefLog.append_entry(tfile, IndexObject.NULL_BIN_SHA, binsha, msg) + entry = RefLog.append_entry(cr, tfile, IndexObject.NULL_BIN_SHA, binsha, msg) assert entry.oldhexsha == IndexObject.NULL_HEX_SHA assert entry.newhexsha == 'f'*40 assert entry.message == msg -- cgit v1.2.3 From 264ba6f54f928da31a037966198a0849325b3732 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 24 Nov 2010 17:12:36 +0100 Subject: Fixed remaining issues, all tests work as expected --- test/test_reflog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/test_reflog.py') diff --git a/test/test_reflog.py b/test/test_reflog.py index 0c8e538b..520be590 100644 --- a/test/test_reflog.py +++ b/test/test_reflog.py @@ -60,7 +60,7 @@ class TestRefLog(TestBase): # test serialize and deserialize - results must match exactly binsha = chr(255)*20 msg = "my reflog message" - cr = repo.config_reader() + cr = self.rorepo.config_reader() for rlp in (rlp_head, rlp_master): reflog = RefLog.from_file(rlp) tfile = os.path.join(tdir, os.path.basename(rlp)) -- cgit v1.2.3 From 98a313305f0d554a179b93695d333199feb5266c Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 24 Nov 2010 19:36:34 +0100 Subject: RefLog: added entry_at method, which is a faster way of reading single entries, including test --- test/test_reflog.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/test_reflog.py') diff --git a/test/test_reflog.py b/test/test_reflog.py index 520be590..5c4a21b8 100644 --- a/test/test_reflog.py +++ b/test/test_reflog.py @@ -79,6 +79,19 @@ class TestRefLog(TestBase): assert entry.newhexsha == 'f'*40 assert entry.message == msg assert RefLog.from_file(tfile)[-1] == entry + + # index entry + # raises on invalid index + self.failUnlessRaises(IndexError, RefLog.entry_at, rlp, 10000) + + # indices can be positive ... + assert isinstance(RefLog.entry_at(rlp, 0), RefLogEntry) + RefLog.entry_at(rlp, 23) + + # ... and negative + for idx in (-1, -24): + RefLog.entry_at(rlp, idx) + #END for each index to read # END for each reflog -- cgit v1.2.3 From 3203cd7629345d32806f470a308975076b2b4686 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 24 Nov 2010 19:48:44 +0100 Subject: Fixed doc strings, improved error checking on RefLog.write method --- test/test_reflog.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/test_reflog.py') diff --git a/test/test_reflog.py b/test/test_reflog.py index 5c4a21b8..3fdf1fae 100644 --- a/test/test_reflog.py +++ b/test/test_reflog.py @@ -56,6 +56,8 @@ class TestRefLog(TestBase): self.failUnlessRaises(ValueError, RefLog.from_file, fixture_path(pp+suffix)) #END for each invalid file + # cannot write an uninitialized reflog + self.failUnlessRaises(ValueError, RefLog().write) # test serialize and deserialize - results must match exactly binsha = chr(255)*20 @@ -65,6 +67,7 @@ class TestRefLog(TestBase): reflog = RefLog.from_file(rlp) tfile = os.path.join(tdir, os.path.basename(rlp)) reflog.to_file(tfile) + assert reflog.write() is reflog # parsed result must match ... treflog = RefLog.from_file(tfile) -- cgit v1.2.3