From 9e841dd4ac8435b97333c380eaa34e7bf01be97e Mon Sep 17 00:00:00 2001 From: Xing Huang Date: Fri, 15 Mar 2024 15:19:15 -0500 Subject: PathFilterGroup: implement getPathsBestEffort() getPathsBestEffort() is a method in the TreeFilter class to retrieve file paths specified by the caller. PathFilterGroup do not propagate the paths of their subfilters as it does not implement the getPathsBestEffort() method, resulting in the caller only getting an empty list of paths. Override getPathsBestEffort() in PathFilterGroup to propagate subfilter values. Signed-off-by: Xing Huang Change-Id: I76bf08795360abc0874a7c258636d4f37da35060 --- .../src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java | 8 ++++++++ .../src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java | 11 +++++++++++ 2 files changed, 19 insertions(+) (limited to 'org.eclipse.jgit') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java index c94160144e..bcf79a285d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java @@ -15,6 +15,10 @@ package org.eclipse.jgit.treewalk.filter; import org.eclipse.jgit.util.RawParseUtils; +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; + /** * Specialized set for byte arrays, interpreted as strings for use in * {@link PathFilterGroup.Group}. Most methods assume the hash is already know @@ -291,4 +295,8 @@ class ByteArraySet { return ret; } + Set toSet() { + return Arrays.stream(toArray()).collect(Collectors.toSet()); + } + } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java index 59855572f2..4c0604ad56 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java @@ -12,6 +12,8 @@ package org.eclipse.jgit.treewalk.filter; import java.util.Collection; +import java.util.Optional; +import java.util.Set; import org.eclipse.jgit.errors.StopWalkException; import org.eclipse.jgit.internal.JGitText; @@ -231,6 +233,15 @@ public class PathFilterGroup { return !prefixes.isEmpty(); } + @Override + public Optional> getPathsBestEffort() { + Set result = fullpaths.toSet(); + if (result.isEmpty()) { + return Optional.empty(); + } + return Optional.of(result); + } + @Override public TreeFilter clone() { return this; -- cgit v1.2.3