libgit2 / libgit2/libgit2sharp
Expose TreeDefinition entry names
Personne n'a encore pris cette issue.
- Langage dominant
- C#
- Étoiles
- 3.5k
- Forks
- 925
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
TreeDefinition has kind of a weird API. You can add to it, remove from it, and get a specific item, but there's no way to get a list of the entries in the tree or the like. For that, you have to commit the TreeDefinition to the ODB to get a regular Tree back, which supports enumeration. This seems ridiculous, not to mention inefficient.
For a recent project, I wanted a way to pass around and modify (several times) tree metadata only, before committing the final version. TreeDefinition worked well for this... until I wanted to look at which entries were in it. I used the above mentioned workaround to convert TreeDefinitions into Trees when I wanted to read their entries. In practice, this was far too slow. Profiling revealed my application was spending 60% of its time writing temporary TreeDefinitions to the ODB. Plus, it was cluttering up the repo with temporary objects.
That led me to create this terrible hack just to be able to use TreeDefinition:
class TreeMetadata : TreeDefinition
{
private static readonly FieldInfo baseEntriesField = typeof(TreeDefinition)
.GetField("entries", BindingFlags.NonPublic | BindingFlags.Instance);
private readonly Dictionary<string, TreeEntryDefinition> baseEntries;
public IEnumerable<string> EntryNames => baseEntries.Keys;
public TreeMetadata()
{
baseEntries = baseEntriesField.GetValue(this) as Dictionary<string, TreeEntryDefinition>;
}
// Snip factory methods copy/pasted from TreeDefinition
}
Would you guys be open to changing the API in some way to make it more usable? I'm not opposed to submitting a PR for it.
Follow-on: is just exposing the entry dictionary keys enough, or should we support full blown dictionary iteration?
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Examinez les API TreeDefinition et Tree afin de comprendre leur comportement actuel pour l’ajout, la suppression, la recherche et l’énumération. Déterminez si la modification prévue expose les noms des entrées ou prend en charge l’itération complète du dictionnaire, puis vérifiez que les métadonnées peuvent être inspectées sans valider d’objets temporaires dans l’ODB.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- csharp, git
- Domaine
- backend-api-design
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100