From 69dd8750be1fbf55010a738dc1ced4655e727f23 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 22 Jun 2010 00:05:37 +0200 Subject: index.write_tree: initial version implemented, although its not yet working correctly, a test to explicitly compare the git version with the python implementation is still missing Tree and Index internally use 20 byte shas, converting them only as needed to reduce memory footprint and processing time objects: started own 'fun' module containing the most important tree functions, more are likely to be added soon --- lib/git/index/typ.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'lib/git/index/typ.py') diff --git a/lib/git/index/typ.py b/lib/git/index/typ.py index b5dac58a..6ef1d2f2 100644 --- a/lib/git/index/typ.py +++ b/lib/git/index/typ.py @@ -5,6 +5,11 @@ from util import ( unpack ) +from binascii import ( + b2a_hex, + a2b_hex + ) + __all__ = ('BlobFilter', 'BaseIndexEntry', 'IndexEntry') #{ Invariants @@ -50,7 +55,7 @@ class BaseIndexEntry(tuple): use numeric indices for performance reasons. """ def __str__(self): - return "%o %s %i\t%s" % (self.mode, self.sha, self.stage, self.path) + return "%o %s %i\t%s" % (self.mode, self.hexsha, self.stage, self.path) @property def mode(self): @@ -58,9 +63,14 @@ class BaseIndexEntry(tuple): return self[0] @property - def sha(self): - """ hex sha of the blob """ + def binsha(self): + """binary sha of the blob """ return self[1] + + @property + def hexsha(self): + """hex version of our sha""" + return b2a_hex(self[1]) @property def stage(self): @@ -88,7 +98,7 @@ class BaseIndexEntry(tuple): @classmethod def from_blob(cls, blob, stage = 0): """:return: Fully equipped BaseIndexEntry at the given stage""" - return cls((blob.mode, blob.sha, stage << CE_STAGESHIFT, blob.path)) + return cls((blob.mode, a2b_hex(blob.sha), stage << CE_STAGESHIFT, blob.path)) class IndexEntry(BaseIndexEntry): @@ -145,12 +155,12 @@ class IndexEntry(BaseIndexEntry): :param base: Instance of type BaseIndexEntry""" time = pack(">LL", 0, 0) - return IndexEntry((base.mode, base.sha, base.flags, base.path, time, time, 0, 0, 0, 0, 0)) + return IndexEntry((base.mode, base.binsha, base.flags, base.path, time, time, 0, 0, 0, 0, 0)) @classmethod def from_blob(cls, blob, stage = 0): """:return: Minimal entry resembling the given blob object""" time = pack(">LL", 0, 0) - return IndexEntry((blob.mode, blob.sha, stage << CE_STAGESHIFT, blob.path, time, time, 0, 0, 0, 0, blob.size)) + return IndexEntry((blob.mode, a2b_hex(blob.sha), stage << CE_STAGESHIFT, blob.path, time, time, 0, 0, 0, 0, blob.size)) -- cgit v1.2.1