| 428 | |
| 429 | |
| 430 | class IndexEntry: |
| 431 | path: str | PathLike[str] |
| 432 | 'The path of this entry' |
| 433 | |
| 434 | id: Oid |
| 435 | 'The id of the referenced object' |
| 436 | |
| 437 | mode: FileMode |
| 438 | 'The mode of this entry, a FileMode value' |
| 439 | |
| 440 | def __init__( |
| 441 | self, path: str | PathLike[str], object_id: Oid, mode: FileMode |
| 442 | ) -> None: |
| 443 | self.path = path |
| 444 | self.id = object_id |
| 445 | self.mode = mode |
| 446 | |
| 447 | @property |
| 448 | def oid(self): |
| 449 | warnings.warn('Use entry.id', DeprecationWarning) |
| 450 | return self.id |
| 451 | |
| 452 | def __str__(self): |
| 453 | return f'<path={self.path} id={self.id} mode={self.mode}>' |
| 454 | |
| 455 | def __repr__(self): |
| 456 | t = type(self) |
| 457 | return f'<{t.__module__}.{t.__qualname__} path={self.path} id={self.id} mode={self.mode}>' |
| 458 | |
| 459 | def __eq__(self, other): |
| 460 | if self is other: |
| 461 | return True |
| 462 | if not isinstance(other, IndexEntry): |
| 463 | return NotImplemented |
| 464 | return ( |
| 465 | self.path == other.path and self.id == other.id and self.mode == other.mode |
| 466 | ) |
| 467 | |
| 468 | def _to_c(self) -> tuple['ffi.GitIndexEntryC', 'ffi.ArrayC[ffi.char]']: |
| 469 | """Convert this entry into the C structure |
| 470 | |
| 471 | The first returned arg is the pointer, the second is the reference to |
| 472 | the string we allocated, which we need to exist past this function |
| 473 | """ |
| 474 | centry = ffi.new('git_index_entry *') |
| 475 | # basically memcpy() |
| 476 | ffi.buffer(ffi.addressof(centry, 'id'))[:] = self.id.raw[:] |
| 477 | centry.mode = int(self.mode) |
| 478 | path = ffi.new('char[]', to_bytes(self.path)) |
| 479 | centry.path = path |
| 480 | |
| 481 | return centry, path |
| 482 | |
| 483 | @classmethod |
| 484 | def _from_c(cls, centry): |
| 485 | if centry == ffi.NULL: |
| 486 | return None |
| 487 |
no outgoing calls
searching dependent graphs…