diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/attributes/FilterCommandRegistry.java b/org.eclipse.jgit/src/org/eclipse/jgit/attributes/FilterCommandRegistry.java index 4729f347d..3fbaedb05 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/attributes/FilterCommandRegistry.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/attributes/FilterCommandRegistry.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.attributes; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.eclipse.jgit.lib.Repository; @@ -102,6 +103,14 @@ public class FilterCommandRegistry { return filterCommandRegistry.containsKey(filterCommandName); } + /** + * @return Set of commandNames for which a {@link FilterCommandFactory} is + * registered + */ + public static Set getRegisteredFilterCommands() { + return filterCommandRegistry.keySet(); + } + /** * Creates a new {@link FilterCommand} for the given name. A factory must be * registered for the name in advance. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java index ff80672f8..f9350a574 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java @@ -391,6 +391,13 @@ public final class Constants { */ public static final String ATTR_FILTER_TYPE_SMUDGE = "smudge"; + /** + * Whether to use JGit's implementations of filters and hooks + * + * @since 4.6 + */ + public static final String ATTR_FILTER_USE_BUILTIN = "useJGitBuiltin"; + /** * Builtin filter commands start with this prefix * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java index 911b7ffa1..21cd6b83a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java @@ -55,6 +55,7 @@ import org.eclipse.jgit.attributes.Attribute; import org.eclipse.jgit.attributes.Attributes; import org.eclipse.jgit.attributes.AttributesNodeProvider; import org.eclipse.jgit.attributes.AttributesProvider; +import org.eclipse.jgit.attributes.FilterCommandRegistry; import org.eclipse.jgit.dircache.DirCacheBuildIterator; import org.eclipse.jgit.attributes.AttributesHandler; import org.eclipse.jgit.dircache.DirCacheIterator; @@ -313,6 +314,8 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { private Config config; + private Set filterCommands; + /** * Create a new tree walker for a given repository. * @@ -357,6 +360,8 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { if (repo != null) { config = repo.getConfig(); attributesNodeProvider = repo.createAttributesNodeProvider(); + filterCommands = FilterCommandRegistry + .getRegisteredFilterCommands(); } else { config = null; attributesNodeProvider = null; @@ -1369,8 +1374,19 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { return filterCommand; filterCommand = config.getString(Constants.ATTR_FILTER, filterDriverName, filterCommandType); - if (filterCommand != null) + boolean useBuiltin = config.getBoolean(Constants.ATTR_FILTER, + filterDriverName, Constants.ATTR_FILTER_USE_BUILTIN, false); + if (useBuiltin) { + String builtinFilterCommand = Constants.BUILTIN_FILTER_PREFIX + + filterDriverName + '/' + filterCommandType; + if (filterCommands != null + && filterCommands.contains(builtinFilterCommand)) { + filterCommand = builtinFilterCommand; + } + } + if (filterCommand != null) { filterCommandsByNameDotType.put(key, filterCommand); + } return filterCommand; } }