1

AFAIK, Repository.Commits property return all commits reachable from current branch.

I would like to get all possible commits, regardless the branch. I am using the following command :

var commitsToRewrite = repository.Branches.SelectMany(x => x.Commits)
                .GroupBy(x => x.Sha)
                .Select(x => x.First())
                .ToArray();

It is slow but it seems to work (maybe I missed some special cases that are not covered). Is this the right way to do ? Is there a more efficient, faster way ?

1 Answer 1

3

Maybe not your case, but in some rare cases i've found that only traversing all branches could skip some commits (may be cause of branch deletion). This piece of code seems to do a better job (hope so), and as a plus is faster and less memory intensive.

var commitsToRewrite = repository.Commits.QueryBy(new CommitFilter {IncludeReachableFrom = repository.Refs.ToList()})
                        .Distinct<Commit>(EqualityComparer<GitObject>.Default)
                        .ToList();

I tested this with ReactOS git repo having more than 85000 commits and 500Mb.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.