summaryrefslogtreecommitdiff
path: root/lib/git/index/typ.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2010-06-22 12:03:53 +0200
committerSebastian Thiel <byronimo@gmail.com>2010-06-22 12:03:53 +0200
commit778234d544b3f58dd415aaf10679d15b01a5281f (patch)
tree57e86ae1ca34f7e3e658b1f078f705ba1b397c10 /lib/git/index/typ.py
parent91725f0fc59aa05ef68ab96e9b29009ce84668a5 (diff)
parentc4f49fb232acb2c02761a82acc12c4040699685d (diff)
downloadgitpython-778234d544b3f58dd415aaf10679d15b01a5281f.tar.gz
Merge branch 'writetree'
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))