aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2019-04-30 19:11:16 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-06-07 17:19:07 +0200
commit10ab407fa6414a1c4ae08696c78e078cce078519 (patch)
treecb619766b8c353f8b447f6870fbae9031d73a75c /org.eclipse.jgit/src/org/eclipse/jgit
parentd2600693bd5fb8bda20bae41467132668caa1e14 (diff)
downloadjgit-10ab407fa6414a1c4ae08696c78e078cce078519.tar.gz
jgit-10ab407fa6414a1c4ae08696c78e078cce078519.zip
DescribeCommand: use glob match instead of path match
Otherwise tags may fail to match if their name contains slashes. Canonical git also uses its wildcard matcher in glob mode.[1] [1] https://github.com/git/git/blob/v2.21.0/builtin/describe.c#L182 Bug: 546703 Change-Id: I122c7959974fa1fc6a53dfc65837e4314a8badd4 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java17
1 files changed, 11 insertions, 6 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
index db3a3d947d..9ad77e65fd 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
@@ -63,8 +63,7 @@ import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.InvalidPatternException;
import org.eclipse.jgit.errors.MissingObjectException;
-import org.eclipse.jgit.ignore.internal.IMatcher;
-import org.eclipse.jgit.ignore.internal.PathMatcher;
+import org.eclipse.jgit.fnmatch.FileNameMatcher;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
@@ -104,7 +103,7 @@ public class DescribeCommand extends GitCommand<String> {
/**
* Pattern matchers to be applied to tags under consideration.
*/
- private List<IMatcher> matchers = new ArrayList<>();
+ private List<FileNameMatcher> matchers = new ArrayList<>();
/**
* Whether to use all tags (incl. lightweight) or not.
@@ -242,7 +241,7 @@ public class DescribeCommand extends GitCommand<String> {
*/
public DescribeCommand setMatch(String... patterns) throws InvalidPatternException {
for (String p : patterns) {
- matchers.add(PathMatcher.createPathMatcher(p, null, false));
+ matchers.add(new FileNameMatcher(p, null));
}
return this;
}
@@ -275,9 +274,15 @@ public class DescribeCommand extends GitCommand<String> {
// Find the first tag that matches in the stream of all tags
// filtered by matchers ordered by tie break order
Stream<Ref> matchingTags = Stream.empty();
- for (IMatcher matcher : matchers) {
+ for (FileNameMatcher matcher : matchers) {
Stream<Ref> m = tags.stream().filter(
- tag -> matcher.matches(tag.getName(), false, false));
+ tag -> {
+ matcher.append(
+ tag.getName().substring(R_TAGS.length()));
+ boolean result = matcher.isMatch();
+ matcher.reset();
+ return result;
+ });
matchingTags = Stream.of(matchingTags, m).flatMap(i -> i);
}
return matchingTags.sorted(TAG_TIE_BREAKER).findFirst();