libgit2 / libgit2/libgit2sharp

Expose TreeDefinition entry names

Offen
#1,473 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
C#
Sterne
3.5k
Forks
925
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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?

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Überprüfe die TreeDefinition- und Tree-APIs, um ihr bestehendes Verhalten beim Hinzufügen, Entfernen, Nachschlagen und Auflisten zu verstehen. Kläre, ob die beabsichtigte Änderung Eintragsnamen offenlegt oder die vollständige Iteration über das Wörterbuch unterstützt, und verifiziere anschließend, dass Metadaten überprüft werden können, ohne temporäre Objekte im ODB zu persistieren.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp, git
Bereich
backend-api-design
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.