libgit2 / libgit2/libgit2sharp
Expose TreeDefinition entry names
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.5k
- Forks
- 925
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the TreeDefinition and Tree APIs to understand their existing add, remove, lookup, and enumeration behavior. Resolve whether the intended change exposes entry names or supports full dictionary iteration, then verify that metadata can be inspected without committing temporary objects to the ODB.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, git
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100