summaryrefslogtreecommitdiff
path: root/lib/git/index.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-11-18 20:34:08 +0100
committerSebastian Thiel <byronimo@gmail.com>2009-11-18 20:34:08 +0100
commit84be1263abac102d8b4bc49096530c6fd45a9b80 (patch)
treefa1682031af923745f02224dd6dc0b32f37e2139 /lib/git/index.py
parent59b05d06c1babcc8cd1c541716ca25452056020a (diff)
downloadgitpython-84be1263abac102d8b4bc49096530c6fd45a9b80.tar.gz
index: Added IndexEntry.from_base method including test in conjunction with symlinks.
Added index.get_entries_key method to allow direct access to anyone willing to do so
Diffstat (limited to 'lib/git/index.py')
-rw-r--r--lib/git/index.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/git/index.py b/lib/git/index.py
index 45bf617f..bd9c73f1 100644
--- a/lib/git/index.py
+++ b/lib/git/index.py
@@ -160,6 +160,19 @@ class IndexEntry(BaseIndexEntry):
return self[10]
@classmethod
+ def from_base(cls, base):
+ """
+ Returns
+ Minimal entry as created from the given BaseIndexEntry instance.
+ Missing values will be set to null-like values
+
+ ``base``
+ Instance of type BaseIndexEntry
+ """
+ time = struct.pack(">LL", 0, 0)
+ return IndexEntry((base.mode, base.sha, base.stage, base.path, time, time, 1, 1, 1, 1, 0))
+
+ @classmethod
def from_blob(cls, blob):
"""
Returns
@@ -219,7 +232,8 @@ class IndexFile(LazyMixin, diff.Diffable):
The index contains an entries dict whose keys are tuples of type IndexEntry
to facilitate access.
- You may only read the entries dict or manipulate it through designated methods.
+ You may read the entries dict or manipulate it using IndexEntry instance, i.e.::
+ index.entries[index.get_entries_key(index_entry_instance)] = index_entry_instance
Otherwise changes to it will be lost when changing the index using its methods.
"""
__slots__ = ( "repo", "version", "entries", "_extension_data", "_file_path" )
@@ -311,7 +325,7 @@ class IndexFile(LazyMixin, diff.Diffable):
self.entries = dict()
while count < num_entries:
entry = self._read_entry(stream)
- self.entries[(entry.path, entry.stage)] = entry
+ self.entries[self.get_entries_key(entry)] = entry
count += 1
# END for each entry
@@ -521,6 +535,18 @@ class IndexFile(LazyMixin, diff.Diffable):
return path_map
+ @classmethod
+ def get_entries_key(cls, entry):
+ """
+ Returns
+ Key suitable to be used for the index.entries dictionary
+
+ ``entry``
+ Instance of type BaseIndexEntry
+ """
+ return (entry.path, entry.stage)
+
+
def resolve_blobs(self, iter_blobs):
"""
Resolve the blobs given in blob iterator. This will effectively remove the