Skip to content

Closes #1472: Implement in-memory config backend for config overrides in context manager#1473

Open
beamerblvd wants to merge 13 commits into
libgit2:masterfrom
beamerblvd:support-in-memory-config
Open

Closes #1472: Implement in-memory config backend for config overrides in context manager#1473
beamerblvd wants to merge 13 commits into
libgit2:masterfrom
beamerblvd:support-in-memory-config

Conversation

@beamerblvd

@beamerblvd beamerblvd commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

This implements #1472. It makes several changes to configs in pygit2, and includes substantial documentation improvements to explain the new classes and methods:

  • Config has several internal changes, but externally, its use and behavior is the same.
  • DefaultConfig is a new class that extends Config and wraps git_config_open_default, which previously was not accessible in pygit2.
  • RepositoryConfig is a new class that extends Config and wraps git_repository_config / git_repository_config_snapshot (previously these were wrapped directly by Config).
  • When DefaultConfig and RepositoryConfig are constructed, they construct an in-memory config backend with level ConfigLevel.APP that, initially, is unused. When instances of these classes are entered as a context manager, that in-memory backend is given sole write priority. When instances of these classes are exited as a context manager, that in-memory backend in cleared, and the default write priority is restored.
  • To address Config iterator crashes if git_config_entry_free used, documentation is unclear if that's intended libgit2#7307 and Access violation accessing repo config entries #970 (properly), the memory management of iterators and ConfigEntry has been refactored.

beamerblvd added 13 commits July 1, 2026 12:59
`Config` now has two subclasses: `DefaultConfig` and `RepositoryConfig`:
- `DefaultConfig` represents the total sum config of program, system,
  XDG, and global (user) configurations as obtained from
`git_config_open_default`. Even if none of those files exist, one can
still create an empty `DefaultConfig`.
- `RepositoryConfig` represents repository configurations and is the
  type now returned by `Repository.config` and
`Repository.config_snapshot`.
- `RepositoryConfig` contains the ability to enter/exit as a context
  manager, enabling an in-memory config backend with level
`GIT_CONFIG_LEVEL_APP`. This allows users to add temporary, in-memory
overrides to the repository config that affect repository operations
without persisting permanently to the repository's config file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant