diff options
author | John Tipper <John_Tipper@hotmail.com> | 2019-12-02 23:00:19 +0000 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2019-12-05 22:38:12 +0100 |
commit | 5bf226d50c96f643e9ee3161155c7ba4e641568a (patch) | |
tree | 74ec154d55fe1b490f589ea9050d105c88188cea /org.eclipse.jgit | |
parent | b24ec8f7159469340e4519b42bf5a57a44b75c38 (diff) | |
download | jgit-5bf226d50c96f643e9ee3161155c7ba4e641568a.tar.gz jgit-5bf226d50c96f643e9ee3161155c7ba4e641568a.zip |
CLI: Add support for excluding paths from Git log command
Git log supports the exclude pathspec, which allows for excluding paths
from the log command. JGit only supports adding paths to the log
command. See the following StackOverflow question for details:
https://stackoverflow.com/questions/59143934/java-jgit-how-to-get-git-
commits-not-affecting-certain-directories
This commit adds an excludePath() method to the log command. It does not
yet support regex or glob wildcards.
Change-Id: I8cd59950b87850b55a15c7e2ea5470145c9aae28
Signed-off-by: John Tipper <john_tipper@hotmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java index 66de8ae131..5ea6015afa 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java @@ -64,10 +64,7 @@ import org.eclipse.jgit.revwalk.filter.AndRevFilter; import org.eclipse.jgit.revwalk.filter.MaxCountRevFilter; import org.eclipse.jgit.revwalk.filter.RevFilter; import org.eclipse.jgit.revwalk.filter.SkipRevFilter; -import org.eclipse.jgit.treewalk.filter.AndTreeFilter; -import org.eclipse.jgit.treewalk.filter.PathFilter; -import org.eclipse.jgit.treewalk.filter.PathFilterGroup; -import org.eclipse.jgit.treewalk.filter.TreeFilter; +import org.eclipse.jgit.treewalk.filter.*; /** * A class used to execute a {@code Log} command. It has setters for all @@ -105,6 +102,7 @@ public class LogCommand extends GitCommand<Iterable<RevCommit>> { private RevFilter revFilter; private final List<PathFilter> pathFilters = new ArrayList<>(); + private final List<TreeFilter> excludeTreeFilters = new ArrayList<>(); private int maxCount = -1; @@ -133,9 +131,22 @@ public class LogCommand extends GitCommand<Iterable<RevCommit>> { @Override public Iterable<RevCommit> call() throws GitAPIException, NoHeadException { checkCallable(); - if (!pathFilters.isEmpty()) - walk.setTreeFilter(AndTreeFilter.create( - PathFilterGroup.create(pathFilters), TreeFilter.ANY_DIFF)); + List<TreeFilter> filters = new ArrayList<>(); + if (!pathFilters.isEmpty()) { + filters.add(AndTreeFilter.create(PathFilterGroup.create(pathFilters), TreeFilter.ANY_DIFF)); + } + if (!excludeTreeFilters.isEmpty()) { + for (TreeFilter f : excludeTreeFilters) { + filters.add(AndTreeFilter.create(f, TreeFilter.ANY_DIFF)); + } + } + if (!filters.isEmpty()) { + if (filters.size() == 1) { + filters.add(TreeFilter.ANY_DIFF); + } + walk.setTreeFilter(AndTreeFilter.create(filters)); + + } if (skip > -1 && maxCount > -1) walk.setRevFilter(AndRevFilter.create(SkipRevFilter.create(skip), MaxCountRevFilter.create(maxCount))); @@ -310,6 +321,24 @@ public class LogCommand extends GitCommand<Iterable<RevCommit>> { } /** + * Show all commits that are not within any of the specified paths. The path + * must either name a file or a directory exactly and use <code>/</code> + * (slash) as separator. Note that regular expressions or wildcards are not + * yet supported. If a path is both added and excluded from the search, then + * the exclusion wins. + * + * @param path + * a repository-relative path (with <code>/</code> as separator) + * @return {@code this} + * @since 5.6 + */ + public LogCommand excludePath(String path) { + checkCallable(); + excludeTreeFilters.add(PathFilter.create(path).negate()); + return this; + } + + /** * Skip the number of commits before starting to show the commit output. * * @param skip |