Skip to content

Add revwalk globs#184

Closed
tclem wants to merge 6 commits into
libgit2:vNextfrom
tclem:add-revwalk-globs
Closed

Add revwalk globs#184
tclem wants to merge 6 commits into
libgit2:vNextfrom
tclem:add-revwalk-globs

Conversation

@tclem

@tclem tclem commented Jun 15, 2012

Copy link
Copy Markdown
Member

This adds in the ability to filter your revwalk by pushing or hiding globs enabling functionality like:

git log --not --remotes or git log --branches

I'm open to suggestions on the filter API. The glob patterns didn't make sense to add in with the rest of the list of stuff that Since and Until know how to deal with because they are never really git objects of any sort. Improving the Filter object gave me the chance to refactor how it was use internally a little bit and pass the filter down a few more layers to get rid of a few ctors with growing parameter lists.

Comment thread LibGit2Sharp.Tests/CommitFixture.cs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing this? What should the following statements be expected to return?

  • repo.Commits.QueryBy(new Filter { Since = null })
  • repo.Commits.QueryBy(new Filter { Since = string.Empty })

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - see aec0563

@nulltoken

Copy link
Copy Markdown
Member

I like the refactoring proposal which pushes the logic inside the Filter type. This is where it belongs.
However, I'm not a fan of publicly exposing the SinceList|UntilList properties. Could you make them internal?

@nulltoken

Copy link
Copy Markdown
Member

Rather than adding a SinceGlob|UntilGlob property to the Filter type, I I'd prefer adding to the ReferenceCollection type a new IEnumerable<Reference> FromGlob(string pattern) method.

This would allow such construct

[Fact]
public void CanEnumerateCommitsUsingGlob()
{
    AssertEnumerationOfCommits(
        repo => new Filter { Since = repo.Refs.FromGlob("heads") },
        new[]
             {
                 "4c062a6", "e90810b", "6dcf9bf", "a4a7dce", "be3563a", "c47800c", "9fd738e", "4a202b3", "41bc8c6", "5001298", "5b5b025", "8496071"
             });
}

@tclem

tclem commented Jun 21, 2012

Copy link
Copy Markdown
Member Author

@nulltoken isn't that going to be expensive in terms of having to lookup all the refs that match the glob pattern? Wouldn't you rather have the existing libgit2 apis for pushing and hiding a glob do that?

@nulltoken

Copy link
Copy Markdown
Member

isn't that going to be expensive in terms of having to lookup all the refs that match the glob pattern? Wouldn't you rather have the existing libgit2 apis for pushing and hiding a glob do that?

Well, behind the scene, this is what git_revwalk_push_glob() does. I'd really like to have this unfolded and allow the API consumer to retrieve a list of refs from a glob, which could be eventually used to retrieve a commit log (or used to a different end).

The fast way would be to quickly implement that in C# on top of the current Refs enumerator (porting the libgit2 normalization algorithm and regex love). If you feel performance may become a concern, instead of the Refs enumerator, one could work against the result of Libgit2UnsafeHelper.ListAllReferenceNames() which would avoid the parsing/building of every reference.

Eventually, once this code is proven ok and covered with some tests, it'll be pushed down in libgit2.

@nulltoken

Copy link
Copy Markdown
Member

Very nice proposal and awesome refactoring!

Manually merged in vNext.

@nulltoken nulltoken closed this Aug 12, 2012
@tclem

tclem commented Aug 12, 2012

Copy link
Copy Markdown
Member Author

Awesome! Thanks @nulltoken!

Sign up for free to 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.

2 participants