summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-11-27 19:50:54 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2018-11-27 19:51:01 +0900
commit28f0ef8509b93588bc0a42e1cf6b51db06da6474 (patch)
tree22fa113293ea223acabf92055e9646844f5e0455 /org.eclipse.jgit
parentf40a5a12e4f8e13c20a08b4408afad4b41f0f302 (diff)
parentdf6263644bb3387239cd77aa57074380610a0ec4 (diff)
downloadjgit-28f0ef8509b93588bc0a42e1cf6b51db06da6474.tar.gz
jgit-28f0ef8509b93588bc0a42e1cf6b51db06da6474.zip
Merge branch 'stable-4.11' into stable-5.0
* stable-4.11: Fix DescribeCommand with multiple match options Fix git-describe tie-breakers Change-Id: Ibb98f143ee0ce7635beb30ec404b4134a73788f6 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java39
1 files changed, 29 insertions, 10 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 4d5e499571..a484742e08 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
@@ -50,10 +50,12 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
@@ -71,6 +73,7 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevFlag;
import org.eclipse.jgit.revwalk.RevFlagSet;
+import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.revwalk.RevWalk;
/**
@@ -224,24 +227,40 @@ public class DescribeCommand extends GitCommand<String> {
return this;
}
+ private final Comparator<Ref> TAG_TIE_BREAKER = new Comparator<Ref>() {
+
+ @Override
+ public int compare(Ref o1, Ref o2) {
+ try {
+ return tagDate(o2).compareTo(tagDate(o1));
+ } catch (IOException e) {
+ return 0;
+ }
+ }
+
+ private Date tagDate(Ref tag) throws IOException {
+ RevTag t = w.parseTag(tag.getObjectId());
+ w.parseBody(t);
+ return t.getTaggerIdent().getWhen();
+ }
+ };
+
private Optional<Ref> getBestMatch(List<Ref> tags) {
if (tags == null || tags.size() == 0) {
return Optional.empty();
} else if (matchers.size() == 0) {
- // No matchers, simply return the first tag entry
+ Collections.sort(tags, TAG_TIE_BREAKER);
return Optional.of(tags.get(0));
} else {
- // Find the first tag that matches one of the matchers; precedence according to matcher definition order
+ // 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) {
- Optional<Ref> match = tags.stream()
- .filter(tag -> matcher.matches(tag.getName(), false,
- false))
- .findFirst();
- if (match.isPresent()) {
- return match;
- }
+ Stream<Ref> m = tags.stream().filter(
+ tag -> matcher.matches(tag.getName(), false, false));
+ matchingTags = Stream.of(matchingTags, m).flatMap(i -> i);
}
- return Optional.empty();
+ return matchingTags.sorted(TAG_TIE_BREAKER).findFirst();
}
}