Skip to content

Add RevWalker - #2038

Open
jairbubbles wants to merge 33 commits into
libgit2:masterfrom
jairbubbles:add-revwalker
Open

Add RevWalker#2038
jairbubbles wants to merge 33 commits into
libgit2:masterfrom
jairbubbles:add-revwalker

Conversation

@jairbubbles

Copy link
Copy Markdown
Contributor

This allows more flexibility than CommitLog and allows to traverse the repository multiple times more efficiently.

usingvarrepository=newRepository(@"<repo_path>");usingvarrevWalker=newRevWalker(repository);// Store commits in a cache to speed up multiple walks on same repositoryvarcommitsCache=newDictionary<ObjectId,Commit>();revWalker.Reset();revWalker.Sorting(CommitSortStrategies.Topological);revWalker.PushGlob("refs/tags/*");varcommits=GetCommits().ToArray();// Subsequent walk will reuse commits cache and internal RevWalker cacherevWalker.Reset();revWalker.PushRef("HEAD");commits=GetCommits().ToArray();IEnumerable<Commit>GetCommits(){while(true){varobjectId=revWalker.Next();if(objectId==null)break;if(!commitsCache.TryGetValue(objectId,outvarcommit)){commit=repository.Lookup<Commit>(objectId);commitsCache[objectId]=commit;}yieldreturncommit;}}

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@jairbubbles@James-LG@bording