libgit2 / libgit2/pygit2

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

オープン
#1,472 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
1.7k
フォーク
408
平均マージ
2日 57分
マージ済み PR(30日)
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. リポジトリをフォークし、ブランチを切って変更します。
  4. 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 を短くまとめたダイジェスト。