2

I'm trying to query for commits:

repo.Commits.QueryBy(new LibGit2Sharp.Filter { Since = repo.Refs }).Take(100)

This is otherwise ok, but it also returns stashes. How can I exclude stashes? I know that when I'm looping through the results I could just ignore them I guess, but then I wouldn't have 100 of them as I wanted.

Tower
  • 98,741
  • 129
  • 357
  • 507

1 Answers1

1

The Since and Until properties of the Filter type are quite tolerant regarding what they can be valued with.

According to the documentation they

Can either be a string containing the sha or reference canonical name to use, a Branch, a Reference, a Commit, a Tag, a TagAnnotation, an ObjectId or even a mixed collection of all of the above.

Basically, Since = repo.Refs means "I want to revwalk from every reference of the repository when enumerating the pointed at commits".

Similarly to git log --all this will indeed consider the branches, the tags, the stash, the notes, ...

If you're willing to reduce the scope of the references, you'll have to select what Since will be valued with.

  • Since = repo.Branches.Where(b => !b.IsRemote)
  • Since = new object[] { repo.Branches["br2"], "refs/heads/master", new ObjectId("e90810b") }

For instance, in order to only consider branches and tags, you'd use

Since = new object[]{ repo.Branches, repo.Tags }

nulltoken
  • 64,429
  • 20
  • 138
  • 130
  • Do you think there's any way to take those commits into account that are not referenced by any branch or the HEAD ref? Basically, loop through EVERY commit in the order of date/creation, no matter if it's referenced or not. – Tower May 31 '12 at 20:23
  • This would require to leverage the reflog and/or git fschk. Those features are not available yet. – nulltoken May 31 '12 at 20:34