libgit2 / libgit2/libgit2sharp
Expose TreeDefinition entry names
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- C#
- Estrelas
- 3.5k
- Forks
- 925
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
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?
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
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.
Avaliação
- Stack de tecnologia
- csharp, git
- Domínio
- backend-api-design
- Tipo de issue
- Funcionalidade
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Status de atividade
- Estagnada
- Clareza
- Precisa de esclarecimento
- Facilidade para iniciantes
- 25/100