libgit2 / libgit2/libgit2sharp

Expose TreeDefinition entry names

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

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

主要言語
C#
スター
3.5k
フォーク
925
PR マージ指標
30日以内にマージされた PR はありません

説明

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?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

TreeDefinition と Tree の API を確認し、既存の追加、削除、検索、列挙の動作を理解します。意図された変更がエントリ名を公開するものなのか、辞書全体の反復処理をサポートするものなのかを明確にし、そのうえで、一時オブジェクトを ODB にコミットせずにメタデータを検査できることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp, git
領域
backend-api-design
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。