@@ -159,6 +159,19 @@ def size(self):
159
159
"""
160
160
return self [10 ]
161
161
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
+
162
175
@classmethod
163
176
def from_blob (cls , blob ):
164
177
"""
@@ -219,7 +232,8 @@ class IndexFile(LazyMixin, diff.Diffable):
219
232
The index contains an entries dict whose keys are tuples of type IndexEntry
220
233
to facilitate access.
221
234
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
223
237
Otherwise changes to it will be lost when changing the index using its methods.
224
238
"""
225
239
__slots__ = ( "repo" , "version" , "entries" , "_extension_data" , "_file_path" )
@@ -311,7 +325,7 @@ def _read_from_stream(self, stream):
311
325
self .entries = dict ()
312
326
while count < num_entries :
313
327
entry = self ._read_entry (stream )
314
- self .entries [(entry . path , entry . stage )] = entry
328
+ self .entries [self . get_entries_key (entry )] = entry
315
329
count += 1
316
330
# END for each entry
317
331
@@ -521,6 +535,18 @@ def unmerged_blobs(self):
521
535
522
536
return path_map
523
537
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
+
524
550
def resolve_blobs (self , iter_blobs ):
525
551
"""
526
552
Resolve the blobs given in blob iterator. This will effectively remove the
0 commit comments