summaryrefslogtreecommitdiff
path: root/git/index/typ.py
diff options
context:
space:
mode:
Diffstat (limited to 'git/index/typ.py')
-rw-r--r--git/index/typ.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/git/index/typ.py b/git/index/typ.py
index 7f27d869..0e64d28c 100644
--- a/git/index/typ.py
+++ b/git/index/typ.py
@@ -1,13 +1,13 @@
"""Module with additional types used by the index"""
from util import (
- pack,
- unpack
- )
+ pack,
+ unpack
+)
from binascii import (
- b2a_hex,
- )
+ b2a_hex,
+)
from git.objects import Blob
__all__ = ('BlobFilter', 'BaseIndexEntry', 'IndexEntry')
@@ -21,7 +21,9 @@ CE_STAGESHIFT = 12
#} END invariants
+
class BlobFilter(object):
+
"""
Predicate to be used by iter_blobs allowing to filter only return blobs which
match the given list of directories or files.
@@ -47,6 +49,7 @@ class BlobFilter(object):
class BaseIndexEntry(tuple):
+
"""Small Brother of an index entry which can be created to describe changes
done to the index in which case plenty of additional information is not requried.
@@ -56,7 +59,7 @@ class BaseIndexEntry(tuple):
def __str__(self):
return "%o %s %i\t%s" % (self.mode, self.hexsha, self.stage, self.path)
-
+
def __repr__(self):
return "(%o, %s, %i, %s)" % (self.mode, self.hexsha, self.stage, self.path)
@@ -69,7 +72,7 @@ class BaseIndexEntry(tuple):
def binsha(self):
"""binary sha of the blob """
return self[1]
-
+
@property
def hexsha(self):
"""hex version of our sha"""
@@ -78,12 +81,12 @@ class BaseIndexEntry(tuple):
@property
def stage(self):
"""Stage of the entry, either:
-
+
* 0 = default stage
* 1 = stage before a merge or common ancestor entry in case of a 3 way merge
* 2 = stage of entries from the 'left' side of the merge
* 3 = stage of entries from the right side of the merge
-
+
:note: For more information, see http://www.kernel.org/pub/software/scm/git/docs/git-read-tree.html
"""
return (self[2] & CE_STAGEMASK) >> CE_STAGESHIFT
@@ -99,16 +102,17 @@ class BaseIndexEntry(tuple):
return self[2]
@classmethod
- def from_blob(cls, blob, stage = 0):
+ def from_blob(cls, blob, stage=0):
""":return: Fully equipped BaseIndexEntry at the given stage"""
return cls((blob.mode, blob.binsha, stage << CE_STAGESHIFT, blob.path))
-
+
def to_blob(self, repo):
""":return: Blob using the information of this index entry"""
- return Blob(repo, self.binsha, self.mode, self.path)
+ return Blob(repo, self.binsha, self.mode, self.path)
class IndexEntry(BaseIndexEntry):
+
"""Allows convenient access to IndexEntry data without completely unpacking it.
Attributes usully accessed often are cached in the tuple whereas others are
@@ -152,7 +156,7 @@ class IndexEntry(BaseIndexEntry):
def size(self):
""":return: Uncompressed size of the blob """
return self[10]
-
+
@classmethod
def from_base(cls, base):
"""
@@ -165,9 +169,7 @@ class IndexEntry(BaseIndexEntry):
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):
+ 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.binsha, stage << CE_STAGESHIFT, blob.path, time, time, 0, 0, 0, 0, blob.size))
-
-