Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter commits by matching a Pattern in a path #10

Open
vmassol opened this issue Jul 12, 2013 · 1 comment
Open

Filter commits by matching a Pattern in a path #10

vmassol opened this issue Jul 12, 2013 · 1 comment

Comments

@vmassol
Copy link

vmassol commented Jul 12, 2013

It would be nice to be able to have a filter that you configure with a path Pattern and it'll return all commits that have modified files matching the path Pattern.

I see there's PatternFindCommitFilter which is close but it's abstract and implementing classes only check in the commit message and not in file paths.

Thanks for this great tool! :)

@vmassol
Copy link
Author

vmassol commented Jul 13, 2013

FTR I've been able to write the following after some research (took me a while to understand that to get the path I needed a DiffEntry :)):

    public class PatternFindPathFilter extends CommitDiffFilter
    {
        private final Matcher matcher;

        public PatternFindPathFilter(String pattern, int flags)
        {
            super(false);
            this.matcher = Pattern.compile(pattern, flags).matcher("");
        }

        @Override
        public boolean include(RevCommit commit, Collection<DiffEntry> diffs) throws IOException
        {
            // If one of the diff entry points to some path matching the pattern then count it in!
            for (DiffEntry diffEntry : diffs) {
                if (this.matcher.reset(diffEntry.getNewPath()).find()) {
                    return true;
                }
            }
            return false;
        }
    }

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

No branches or pull requests

1 participant