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 摘要。