An entry in a configuration object.
| 320 | |
| 321 | |
| 322 | class ConfigEntry: |
| 323 | """An entry in a configuration object.""" |
| 324 | |
| 325 | _entry: 'GitConfigEntryC' |
| 326 | iterator: ConfigIterator | None |
| 327 | |
| 328 | @classmethod |
| 329 | def _from_c( |
| 330 | cls, ptr: 'GitConfigEntryC', iterator: ConfigIterator | None = None |
| 331 | ) -> 'ConfigEntry': |
| 332 | """Builds the entry from a ``git_config_entry`` pointer. |
| 333 | |
| 334 | ``iterator`` must be a ``ConfigIterator`` instance if the entry was |
| 335 | created during ``git_config_iterator`` actions. |
| 336 | """ |
| 337 | entry = cls.__new__(cls) |
| 338 | entry._entry = ptr |
| 339 | entry.iterator = iterator |
| 340 | |
| 341 | # It should be enough to keep a reference to iterator, so we only call |
| 342 | # git_config_iterator_free when we've deleted all ConfigEntry objects. |
| 343 | # But it's not, to reproduce the error comment the lines below and run |
| 344 | # the script in https://github.com/libgit2/pygit2/issues/970 |
| 345 | # So instead we load the Python object immediately. Ideally we should |
| 346 | # investigate libgit2 source code. |
| 347 | if iterator is not None: |
| 348 | entry.raw_name = entry.raw_name |
| 349 | entry.raw_value = entry.raw_value |
| 350 | entry.level = entry.level |
| 351 | |
| 352 | return entry |
| 353 | |
| 354 | def __del__(self) -> None: |
| 355 | if self.iterator is None: |
| 356 | C.git_config_entry_free(self._entry) |
| 357 | |
| 358 | @property |
| 359 | def c_value(self) -> 'ffi.char_pointer': |
| 360 | """The raw ``cData`` entry value.""" |
| 361 | return self._entry.value |
| 362 | |
| 363 | @cached_property |
| 364 | def raw_name(self) -> bytes: |
| 365 | return ffi.string(self._entry.name) |
| 366 | |
| 367 | @cached_property |
| 368 | def raw_value(self) -> bytes | None: |
| 369 | return ffi.string(self.c_value) if self.c_value != ffi.NULL else None |
| 370 | |
| 371 | @cached_property |
| 372 | def level(self) -> int: |
| 373 | """The entry's ``git_config_level_t`` value.""" |
| 374 | return self._entry.level |
| 375 | |
| 376 | @property |
| 377 | def name(self) -> str: |
| 378 | """The entry's name.""" |
| 379 | return self.raw_name.decode('utf-8') |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…