libgit2 / libgit2/libgit2sharp

Expose TreeDefinition entry names

未關閉
#1,473 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
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. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

檢查 TreeDefinition 和 Tree API,了解其現有的新增、移除、查找和列舉行為。確定預期的變更是公開項目名稱,還是支援完整的字典迭代,然後驗證無需將暫存物件提交至 ODB 即可檢查中繼資料。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
csharp, git
領域
backend-api-design
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。