summaryrefslogtreecommitdiff
path: root/lib/git/index/typ.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-06-22 00:05:37 +0200
committerSebastian Thiel <byronimo@gmail.com>2010-06-22 00:05:37 +0200
commit69dd8750be1fbf55010a738dc1ced4655e727f23 (patch)
tree1d49d5ff0218a358d63ae1cab93c56731cc5ea46 /lib/git/index/typ.py
parent1044116d25f0311033e0951d2ab30579bba4b051 (diff)
downloadgitpython-69dd8750be1fbf55010a738dc1ced4655e727f23.tar.gz
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
Diffstat (limited to 'lib/git/index/typ.py')
-rw-r--r--lib/git/index/typ.py22
1 files changed, 16 insertions, 6 deletions
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))