Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] Using Filters with JGit to Implement Include and Exclude Paths

Hey JGit community.  I am fairly new to JGit so forgive me if this question have been answered before but here is my situation.


I am trying to implement a way to get a list of revisions on a git repository based on include and exclude path filters that I give it.


So this is what I originally had in mind:

TreeFilter includeFilter = PathFilterGroup.createfromStrings(includePaths);

TreeFilter excludeFilter = NotTreeFilter.create(PathFilterGroup.createFromStrings(excludePaths));


TreeFilter pathFilter = AndTreeFilter.create(includeFilter, excludeFilter);



Now obviously this is just a simplified version that doesn’t take into account empty include and exclude path lists and the inclusion of the “/” in either list.  But this is just an idea of what I was thinking. 


After writing tests for this setup it wasn’t working and I came to the conclusion that I didn’t want the quick abort feature of PathFilterGroup so I switched to using something like this:


TreeFilter includeFilter = OrTreeFilter.create(includePathFiltersArray);

TreeFilter excludeFilter = NotTreeFilter.create(OrTreeFilter.create (excludePathFiltersArray));


TreeFilter pathFilter = AndTreeFilter.create(includeFilter, excludeFilter);



However now I am noticing that the Exclude Filter is not behaving as I would expect it to.  I guess that makes sense as it seems that allot of these filters are not designed to handle the type of filter wrapping that I am trying to do.  It seems like the Exclude Filter doesn’t keep trying to filter recursively as I would expect it to.


I was looking for documentation on what I was trying to do but I couldn’t find anything.  Does anyone have any ideas or resources that could help me out?  Thanks for your time.



Evan Knapp
Software Engineer Int - PD,
JDA Software | 20700 Swenson Drive, Waukesha, WI 53186

1.262.317.2159 | office
| worldwide
email | Evan.Knapp@xxxxxxx
visit us


Don’t Miss FOCUS 2015 Orlando – over 100 customer-led sessions and 1 Grammy-winning singer! Learn More >

Back to the top