diff options
author | Dave Borowitz <dborowitz@google.com> | 2014-06-12 10:04:01 -0700 |
---|---|---|
committer | Dave Borowitz <dborowitz@google.com> | 2014-06-12 13:52:09 -0700 |
commit | eb69cef35c2fa9d6f1f8493e3ae03cd65b86b5cc (patch) | |
tree | ea679416040bec689d1af7868b709bf4346c4507 /org.eclipse.jgit/src/org/eclipse/jgit/revwalk | |
parent | 2a562b94d64daeff220bb7e0fbb5cb63720d824c (diff) | |
download | jgit-eb69cef35c2fa9d6f1f8493e3ae03cd65b86b5cc.tar.gz jgit-eb69cef35c2fa9d6f1f8493e3ae03cd65b86b5cc.zip |
Rename RewriteTreeFilter to TreeRevFilter and make it public
The current behavior of passing a TreeFilter to RevWalk has limited
usefulness, since the RevFilter derived from the TreeFilter is always
ANDed together with any other RevFilters. It is also tied fairly
tightly to the parent rewriting mechanism.
Make TreeRevFilter a generic RevFilter that matches modified paths
against any TreeFilter. This allows for more complex logic like
(modified this path OR authored by this person).
Leave the rewrite flag logic in this class, since it's closely tied to
the parent comparison code, but hidden behind a protected constructor.
Change-Id: Ia72ef591a99415e6f340c5f64583a49c91f1b82f
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/revwalk')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java | 4 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/revwalk/StartGenerator.java | 3 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java (renamed from org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteTreeFilter.java) | 67 |
3 files changed, 54 insertions, 20 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java index 87a56a9e8f..3ab96ca228 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java @@ -57,7 +57,7 @@ import org.eclipse.jgit.errors.MissingObjectException; * commit that matched the revision walker's filters. * <p> * This generator is the second phase of a path limited revision walk and - * assumes it is receiving RevCommits from {@link RewriteTreeFilter}, + * assumes it is receiving RevCommits from {@link TreeRevFilter}, * after they have been fully buffered by {@link AbstractRevQueue}. The full * buffering is necessary to allow the simple loop used within our own * {@link #rewrite(RevCommit)} to pull completely through a strand of @@ -66,7 +66,7 @@ import org.eclipse.jgit.errors.MissingObjectException; * this loop to abort early, due to commits not being parsed and colored * correctly. * - * @see RewriteTreeFilter + * @see TreeRevFilter */ class RewriteGenerator extends Generator { private static final int REWRITE = RevWalk.REWRITE; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/StartGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/StartGenerator.java index 9c4e53c979..aab678cd7b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/StartGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/StartGenerator.java @@ -127,7 +127,8 @@ class StartGenerator extends Generator { else pending = new DateRevQueue(q); if (tf != TreeFilter.ALL) { - rf = AndRevFilter.create(new RewriteTreeFilter(w, tf), rf); + rf = AndRevFilter.create( + new TreeRevFilter(w, tf, RevWalk.REWRITE), rf); pendingOutputType |= HAS_REWRITE; if (w.getRewriteParents()) pendingOutputType |= NEEDS_REWRITE; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteTreeFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java index a84e80e650..b2c0fcdf73 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteTreeFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java @@ -60,32 +60,65 @@ import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.filter.TreeFilter; /** - * First phase of a path limited revision walk. - * <p> - * This filter is ANDed to evaluate after all other filters and ties the - * configured {@link TreeFilter} into the revision walking process. + * Filter applying a {@link TreeFilter} against changed paths in each commit. * <p> * Each commit is differenced concurrently against all of its parents to look - * for tree entries that are interesting to the TreeFilter. If none are found - * the commit is colored with {@link RevWalk#REWRITE}, allowing a later pass - * implemented by {@link RewriteGenerator} to remove those colored commits from - * the DAG. + * for tree entries that are interesting to the {@link TreeFilter}. * - * @see RewriteGenerator + * @since 3.5 */ -class RewriteTreeFilter extends RevFilter { +public class TreeRevFilter extends RevFilter { private static final int PARSED = RevWalk.PARSED; private static final int UNINTERESTING = RevWalk.UNINTERESTING; - private static final int REWRITE = RevWalk.REWRITE; - + private final int rewriteFlag; private final TreeWalk pathFilter; - RewriteTreeFilter(final RevWalk walker, final TreeFilter t) { + /** + * Create a {@link RevFilter} from a {@link TreeFilter}. + * + * @param walker + * walker used for reading trees. + * @param t + * filter to compare against any changed paths in each commit. If a + * {@link FollowFilter}, will be replaced with a new filter + * following new paths after a rename. + * @since 3.5 + */ + public TreeRevFilter(final RevWalk walker, final TreeFilter t) { + this(walker, t, 0); + } + + + /** + * Create a filter for the first phase of a parent-rewriting limited revision + * walk. + * <p> + * This filter is ANDed to evaluate before all other filters and ties the + * configured {@link TreeFilter} into the revision walking process. + * <p> + * If no interesting tree entries are found the commit is colored with + * {@code rewriteFlag}, allowing a later pass implemented by + * {@link RewriteGenerator} to remove those colored commits from the DAG. + * + * @see RewriteGenerator + * + * @param walker + * walker used for reading trees. + * @param t + * filter to compare against any changed paths in each commit. If a + * {@link FollowFilter}, will be replaced with a new filter + * following new paths after a rename. + * @param rewriteFlag + * flag to color commits to be removed from the simplified DAT. + */ + TreeRevFilter(final RevWalk walker, final TreeFilter t, + final int rewriteFlag) { pathFilter = new TreeWalk(walker.reader); pathFilter.setFilter(t); pathFilter.setRecursive(t.shouldBeRecursive()); + this.rewriteFlag = rewriteFlag; } @Override @@ -128,7 +161,7 @@ class RewriteTreeFilter extends RevFilter { // No changes, so our tree is effectively the same as // our parent tree. We pass the buck to our parent. // - c.flags |= REWRITE; + c.flags |= rewriteFlag; return false; } else { // We have interesting items, but neither of the special @@ -149,7 +182,7 @@ class RewriteTreeFilter extends RevFilter { // if (tw.next()) return true; - c.flags |= REWRITE; + c.flags |= rewriteFlag; return false; } @@ -192,7 +225,7 @@ class RewriteTreeFilter extends RevFilter { continue; } - c.flags |= REWRITE; + c.flags |= rewriteFlag; c.parents = new RevCommit[] { p }; return false; } @@ -223,7 +256,7 @@ class RewriteTreeFilter extends RevFilter { // as they are and allow those parents to flow into pending // for further scanning. // - c.flags |= REWRITE; + c.flags |= rewriteFlag; return false; } |