]> source.dussan.org Git - jgit.git/commit
Correct the boolean logic for filtering paths 32/91432/6
authorMagnus Vigerlöf <magnus.vigerlof@gmail.com>
Sat, 18 Feb 2017 18:28:39 +0000 (19:28 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 28 Feb 2017 22:56:33 +0000 (23:56 +0100)
commit2a5d20c138b0e16160329e9030d56158da9ceffb
treea4395d4abd522434b8b0a8cc6e0126c1463f3220
parentb24c8fca49bfa0dcaef094a7630b7b334f966fbc
Correct the boolean logic for filtering paths

The TreeWalk filtering classes need to support the three different
meanings of the return value the path comparison generates.
A new path comparison method (isPathMatch) is created with
three distinct return values (isPathPrefix use value '0' to
encode two of these) which will makes it possible for the logical
operators (especially NOT) to aggregate a correct verdict.

A filter like: AND(Path("path"), NOT(Path("path/to/other")))
Should filter out 'path/to/other/file', but not 'path/to/my/file'.

The path-limiting feature when testing path/to/my/file, would
result to run test for the following paths:

    path
    path/to
    path/to/my
    path/to/my/file

isPathPrefix('path/to/other') will return '0' for the first two
and since there is no way for NOT to distinguish between an exact
match and a match indicating that the tested path is a 'parent',
it will incorrectly return false and thus remove everything below
'path' immediately.
isPathMatch has a distinguished value for 'parent' matches that
will be preserved through the logic operators and should not
cause an over-eager removal of paths.

The functionality of isPathPrefix is required by other parts
and is untouched.

Unit tests are included to ensure that the logical functionality
is correct and can be preserved.

Change-Id: Ice2ca9406f09f1b179569e99b86a0e5d77baa20d
Signed-off-by: Magnus Vigerlöf <magnus.vigerlof@gmail.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterLogicTest.java [new file with mode: 0644]
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/AndTreeFilter.java
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/NotTreeFilter.java
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/OrTreeFilter.java
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilter.java
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/TreeFilter.java