KeyNotFoundException when trying to iterate through QueryBy result set.
See original GitHub issueI’m trying to get all commits that a particular file is associated with. This is the code that I’m running:
IEnumerable<LogEntry> fileHistory = repo.Commits.QueryBy(fileRelativePath);
foreach (LogEntry version in fileHistory){
// do something...
}
The foreach throws a KeyNotFoundException. Any idea on how to overcome this?
I’m using: LibGit2Sharp.0.23.1
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Unable to iterate commits on all branches for a specific ...
When you attempt to use repository.QueryBy(string, CommitFilter) and specify all branches as the IncludeReachableFrom parameter, a KeyNotFound ...
Read more >KeyNotFoundException when iterating through Dictionary
This is coming from the "if" statement in the loop. To me, this implies that the iterator has become desynchronised from the actual...
Read more >Wiql query by id. This example below is made for an Azure ...
A query defined using the Work Item Query Language (WIQL) consists of a SELECT statement that lists the fields to be returned as...
Read more >How to Iterate Through a Dictionary in Python
In this step-by-step tutorial, you'll take a deep dive into how to iterate through a dictionary in Python. Dictionaries are a fundamental data...
Read more >Iterate Through the Keys of an Object with a for...in Statement
In this basic data structures tutorial we iterate through the keys of an object with a for...in statement. This makes up one part...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I faced the same issue. It is not necessary to change library source code to avoid this issue. It’s possible to provide custom CommitFilter with Topological sorting. FullHistory adds each parent of current commit to the map and expects to find each commit on the map. But some commits may appear in the timeline before their children and this leads to KeyNotFoundException. Maybe it’s better to allow Topological sorting only? The patch @japf suggested breaks tracking of renamed files.
Specifying Topological sorting does not seem to fix the issue. If anyone wants to take a crack at this, here are a couple of files that reproduce the issue using the latest version on nuget (0.25.2). git-repo.zip Program.cs.txt
Edit: After a closer look, this does not appear to be the same issue, but it is related. My issue is stemming from the fact that I am iterating commits for a specific path from multiple branch starting points. Given the following history for a single file:
Iterating
repository.Commits.QueryBy("change.sql", new CommitFilter { IncludeReachableFrom = repository.Branches })
will always throw a key not found exception.git log --all --graph --pretty=oneline change.sql
prints the above graph, so it does seem like a bug.Edit 2: I’ve opened a new issue #1599 for my problem since it doesn’t seem like the same issue and the topological sorting workaround doesn’t work in this case.