libgit2 / libgit2/pygit2

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

Ouverte
#1,472 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
Python
Étoiles
1.7k
Forks
408
Merge moyen
2 j 57 min
PR mergées (30 j)
7

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par examiner la classe Config existante et les wrappers proposés DefaultConfig et RepositoryConfig autour de git_config_open_default et git_repository_config. Vérifiez comment le backend APP en mémoire doit se comporter en tant que gestionnaire de contexte, puis vérifiez que les opérations Git ne voient les remplacements qu’à l’intérieur du contexte et que les modifications ne persistent pas après la sortie.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
git, python
Domaine
backend, tooling
Type d'issue
Fonctionnalité
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.