libgit2 / libgit2/pygit2

Feature Request: Support app-level temporary config overrides using libgit2's backend supprt

未关闭
#1,472 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
1.7k
派生
408
平均合并
2 天 57 分钟
30 天内合并 PR
7

描述

When using the git CLI, you can temporarily override / add config values with -c <name>=<value> (and also --config-env=<name>=<envvar>, but that's just a wrapper around -c to keep secret values off the command line). The important key to -c is that it doesn't persist to a file—the config value lives only so long as that process executes, and then it goes away. Pygit2 has no such support for temporary overrides like this—any changes to a Config persist to disk.

libgit2 can support this using config backends. Currently, libgit2 comes with two kinds of config backends—file backends (the standard type) and a read-only in-memory backend constructed from strings. We could, in theory, use the read-only in-memory backend, but its use wouldn't be very Pythonic, and also it's not until the unreleased libgit 1.9.5 that it's possible to construct this backend from the public API (prior to 1.9.5, it was private).

But libgit2's public API supports implementing and attaching any arbitrary custom backend, and it's fairly straightforward (if not verbose) to implement a mutable in-memory backend with CFFI + Python.

As an aside, pygit2 is also lacking a wrapper around git_config_open_default, which is relevant to the approach I'm taking.

With the pull request I'm posting shortly, Config (without any public API breakage) becomes a fully-functional base class that, on its own, does what it has always done: wraps access to configuration files. Two new classes DefaultConfig and RepositoryConfig now extend Config: the former wrapping git_config_open_default and the latter wrapping git_repository_config/git_repository_config_snapshot. Both of these subclasses can now act as context managers for in-memory config overrides. An in-memory backend attached with level APP supports these overrides. When the context manager is entered, the in-memory backend is made the highest priority for writes. When the context manager is exited, the in-memory backend is cleared and made the lowest priority for writes. Within the scope of this context manager, Git operations use these overrides. A hypothetical Python-based alternative Git CLI could, then, implement -c and --config-env using this context manager.

The detailed documentation I have written for these classes explains in more detail.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先检查现有的 Config 类,以及围绕 git_config_open_default 和 git_repository_config 提出的 DefaultConfig 和 RepositoryConfig 封装器。检查内存中的 APP 后端作为上下文管理器应如何运行,然后验证 Git 操作只能在上下文内部看到覆盖项,并且退出后更改不会持久化。

由索引模型根据 Issue 内容生成。

评估

技术栈
git, python
领域
backend, tooling
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。