Skip to content

Commit 5d54424

Browse files
committed
Implement the rest of the code review feedback and fix bugs
- Removed `_weak_config` and the config reference cycle entirely in order to prevent hanging on PyPy garbage collection. Instead of the backend holding a reference to its owning config, the backend stores its own exceptions and the config checks its own stored exception plus the backend's stored exception. - Refactored backend iteration so that it does not hold a lock indefinitely in order to prevent deadlock on PyPy. - Fixed order of levels returned by `DefaultConfig._default_write_order()`. - Refactored backend entries to support round-tripping non-decodable binary data and modified a few test assertions to test this round-trip. - Renamed `Config._get_entry` to `Config.get_entry` and documented it, because without it there's not currently a public way to get a single entry with a binary (non-decodable) value without iterating the single entry as a multivar. - Fixed incorrect and incomplete documentation in `Config.__getitem__`. - Fixed type of first argument for FFI stub of `GitConfigIteratorC.next` (for real this time ... I forgot to `git add` the change last time). - Removed `del_` stub and added comment about why there's no `del` stub. - Added clarifying comments to `clear()` to explain why it's safe.
1 parent 0eb09ba commit 5d54424

3 files changed

Lines changed: 120 additions & 79 deletions

File tree

‎pygit2/_libgit2/ffi.pyi‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class GitConfigC:
204204
class GitConfigIteratorC:
205205
backend: 'GitConfigBackendC'
206206
flags: int
207-
next: Callable[['GitConfigBackendEntryC', GitConfigIteratorC], int]
207+
next: Callable[['_Pointer[GitConfigBackendEntryC]', GitConfigIteratorC], int]
208208
free: Callable[[GitConfigIteratorC], None]
209209

210210
class GitConfigEntryC:
@@ -232,8 +232,11 @@ class GitConfigBackendC:
232232
set_multivar: Callable[
233233
[GitConfigBackendC, char_pointer, char_pointer, char_pointer], int
234234
]
235-
# this unfortunate name is actually `del`, but that conflicts with a Python keyword
236-
del_: Callable[[GitConfigBackendC, char_pointer], int]
235+
# struct git_config_backend contains the following member here that cannot be
236+
# represented with a Python attribute due to its name conflicting with Python's
237+
# 'del' keyword. CFFI has a workaround for this with other Python keywords
238+
# (underscore suffix to the attribute name), but not for `del`:
239+
# (*del)(struct git_config_backend *, const char *)
237240
del_multivar: Callable[[GitConfigBackendC, char_pointer, char_pointer], int]
238241
iterator: Callable[[_Pointer[GitConfigIteratorC], GitConfigBackendC], int]
239242
snapshot: Callable[[_Pointer[GitConfigBackendC], GitConfigBackendC], int]

0 commit comments

Comments
 (0)