@@ -159,6 +159,19 @@ def size(self):
159159 """
160160 return self [10 ]
161161
162+ @classmethod
163+ def from_base (cls , base ):
164+ """
165+ Returns
166+ Minimal entry as created from the given BaseIndexEntry instance.
167+ Missing values will be set to null-like values
168+
169+ ``base``
170+ Instance of type BaseIndexEntry
171+ """
172+ time = struct .pack (">LL" , 0 , 0 )
173+ return IndexEntry ((base .mode , base .sha , base .stage , base .path , time , time , 1 , 1 , 1 , 1 , 0 ))
174+
162175 @classmethod
163176 def from_blob (cls , blob ):
164177 """
@@ -219,7 +232,8 @@ class IndexFile(LazyMixin, diff.Diffable):
219232 The index contains an entries dict whose keys are tuples of type IndexEntry
220233 to facilitate access.
221234
222- You may only read the entries dict or manipulate it through designated methods.
235+ You may read the entries dict or manipulate it using IndexEntry instance, i.e.::
236+ index.entries[index.get_entries_key(index_entry_instance)] = index_entry_instance
223237 Otherwise changes to it will be lost when changing the index using its methods.
224238 """
225239 __slots__ = ( "repo" , "version" , "entries" , "_extension_data" , "_file_path" )
@@ -311,7 +325,7 @@ def _read_from_stream(self, stream):
311325 self .entries = dict ()
312326 while count < num_entries :
313327 entry = self ._read_entry (stream )
314- self .entries [(entry . path , entry . stage )] = entry
328+ self .entries [self . get_entries_key (entry )] = entry
315329 count += 1
316330 # END for each entry
317331
@@ -521,6 +535,18 @@ def unmerged_blobs(self):
521535
522536 return path_map
523537
538+ @classmethod
539+ def get_entries_key (cls , entry ):
540+ """
541+ Returns
542+ Key suitable to be used for the index.entries dictionary
543+
544+ ``entry``
545+ Instance of type BaseIndexEntry
546+ """
547+ return (entry .path , entry .stage )
548+
549+
524550 def resolve_blobs (self , iter_blobs ):
525551 """
526552 Resolve the blobs given in blob iterator. This will effectively remove the
0 commit comments