diff options
author | Marcel Trautwein <me+eclipse@childno.de> | 2018-02-23 07:27:52 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2018-06-13 09:37:47 +0200 |
commit | 5429d1a0cff593bf28186c38fde7e41798a2c0b8 (patch) | |
tree | 5f144268f32ecb4b773b40a64f503526d83bc814 /org.eclipse.jgit/src/org/eclipse | |
parent | 01c52a58f66e1582e5c0cea17801fb347f3163c9 (diff) | |
download | jgit-5429d1a0cff593bf28186c38fde7e41798a2c0b8.tar.gz jgit-5429d1a0cff593bf28186c38fde7e41798a2c0b8.zip |
Make JGit describe behaves same as c-git for lightweight tags
JGit now considers lightweight tags only if the --tags option is set
i.e. `git.describe().setAllTags(true)` has to be set, else the default
is now as in c git:
Only annotated tags are evaluated unless you pass true
equivalent to --tags (or --all) by the option setAllTags.
Hint: This (still) doesn't address any difference between c-git
`--all` and `!--all --tags` behavior;
perhaps this might be a follow up request
Bug: 423206
Change-Id: I9a3699756df0b9c6a7c74a7e8887dea0df17c8e7
Signed-off-by: Marcel Trautwein <me+eclipse@childno.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java | 44 |
1 files changed, 42 insertions, 2 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 dc605a91e5..4d5e499571 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java @@ -104,6 +104,11 @@ public class DescribeCommand extends GitCommand<String> { private List<IMatcher> matchers = new ArrayList<>(); /** + * Whether to use all tags (incl. lightweight) or not + */ + private boolean useTags = false; + + /** * Constructor for DescribeCommand. * * @param repo @@ -173,6 +178,22 @@ public class DescribeCommand extends GitCommand<String> { return this; } + /** + * Instead of using only the annotated tags, use any tag found in refs/tags + * namespace. This option enables matching lightweight (non-annotated) tags + * or not. + * + * @param tags + * <code>true</code> enables matching lightweight (non-annotated) + * tags like setting option --tags in c git + * @return {@code this} + * @since 5.0 + */ + public DescribeCommand setTags(boolean tags) { + this.useTags = tags; + return this; + } + private String longDescription(Ref tag, int depth, ObjectId tip) throws IOException { return String.format( @@ -246,13 +267,14 @@ public class DescribeCommand extends GitCommand<String> { public String call() throws GitAPIException { try { checkCallable(); - - if (target == null) + if (target == null) { setTarget(Constants.HEAD); + } Collection<Ref> tagList = repo.getRefDatabase() .getRefsByPrefix(R_TAGS); Map<ObjectId, List<Ref>> tags = tagList.stream() + .filter(this::filterLightweightTags) .collect(Collectors.groupingBy(this::getObjectIdFromRef)); // combined flags of all the candidate instances @@ -376,4 +398,22 @@ public class DescribeCommand extends GitCommand<String> { w.close(); } } + + /** + * Whether we use lightweight tags or not for describe Candidates + * + * @param ref + * reference under inspection + * @return true if it should be used for describe or not regarding + * {@link org.eclipse.jgit.api.DescribeCommand#useTags} + */ + @SuppressWarnings("null") + private boolean filterLightweightTags(Ref ref) { + ObjectId id = ref.getObjectId(); + try { + return this.useTags || (id != null && (w.parseTag(id) != null)); + } catch (IOException e) { + return false; + } + } } |