Expose TreeDefinition entry names

Aberta
#1,473 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
5/5
Tempo estimado
Mais de uma semana
Facilidade para iniciantes
25/100
Tipo de issue
Funcionalidade
Clareza
Precisa de esclarecimento
Status de atividade
Estagnada
Stack de tecnologia
csharp, git

Direção de pesquisa

Revise as APIs TreeDefinition e Tree para entender seu comportamento existente de adição, remoção, busca e enumeração. Determine se a alteração pretendida expõe os nomes das entradas ou oferece suporte à iteração completa do dicionário e, em seguida, verifique se os metadados podem ser inspecionados sem fazer commit de objetos temporários no ODB.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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?

Linguagem predominante
C#
Estrelas
3.5k
Forks
925
Métricas de merge de PRs
Nenhum PR com merge em 30d

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de libgit2/libgit2sharp

Todas as issues de libgit2/libgit2sharp

Issues semelhantes

Mais issues de C#

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.