diff options
-rw-r--r-- | TODO | 6 | ||||
-rw-r--r-- | lib/git/index.py | 55 | ||||
-rw-r--r-- | test/git/test_index.py | 14 |
3 files changed, 70 insertions, 5 deletions
@@ -58,8 +58,4 @@ Tree * Work through test and check for test-case cleanup and completeness ( what about testing whether it raises on invalid input ? ). See 6dc7799d44e1e5b9b77fd19b47309df69ec01a99 - Also assure that the test-case setup is a bit more consistent ( Derive from TestCase, possibly - make repo a class member instead of an instance member -* Derive from Iterable, simple pipe it through to Commit objects and iterate using - commit.tree. - - + make repo a class member instead of an instance member diff --git a/lib/git/index.py b/lib/git/index.py index 1e67d6d1..1ce4183b 100644 --- a/lib/git/index.py +++ b/lib/git/index.py @@ -10,6 +10,7 @@ manipulations such as querying and merging. import struct import binascii import mmap +import objects class IndexEntry(tuple): """ @@ -17,7 +18,61 @@ class IndexEntry(tuple): Attributes usully accessed often are cached in the tuple whereas others are unpacked on demand. + + See the properties for a mapping between names and tuple indices. """ + @property + def path(self): + return self[0] + + @property + def ctime(self): + """ + Returns + Tuple(int_time_seconds_since_epoch, int_nano_seconds) of the + file's creation time + """ + return struct.unpack(">LL", self[1]) + + @property + def mtime(self): + """ + See ctime property, but returns modification time + """ + return struct.unpack(">LL", self[2]) + + @property + def dev(self): + return self[3] + + @property + def inode(self): + return self[4] + + @property + def mode(self): + return self[5] + + @property + def uid(self): + return self[6] + + @property + def gid(self): + return self[7] + + @property + def data_size(self): + return self[8] + + @property + def sha(self): + return self[9] + + @property + def path_size(self): + return self[10] + class Index(object): """ diff --git a/test/git/test_index.py b/test/git/test_index.py index 272e68b3..91ce22fd 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -6,6 +6,7 @@ from test.testlib import * from git import * +import inspect class TestTree(TestCase): @@ -14,6 +15,19 @@ class TestTree(TestCase): cls.repo = Repo(GIT_REPO) def test_base(self): + # read from file index = Index.from_file(fixture_path("index")) assert index.entries assert index.version > 0 + + # test entry + last_val = None + entry = index.entries.itervalues().next() + for name, method in inspect.getmembers(entry,inspect.ismethod): + val = method(entry) + assert val != last_val + last_val = val + # END for each method + + # write + self.fail("writing, object type and stage") |