Skip to content

Commit

Permalink
refactor: simplify GitUtil.tag_pointsAt
Browse files Browse the repository at this point in the history
  • Loading branch information
qoomon committed Feb 18, 2021
1 parent bd2d24a commit 6eaaa00
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/main/java/me/qoomon/gitversioning/commons/GitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,18 @@ public static String branch(Repository repository) throws IOException {
}

public static List<String> tag_pointsAt(Repository repository, String revstr) throws IOException {
ObjectId rev = repository.resolve(revstr);

ObjectId revObjectId = repository.resolve(revstr);
List<String> tagNames = new ArrayList<>();
for (Ref ref : repository.getRefDatabase().getRefsByPrefix(R_TAGS)) {
ref = repository.getRefDatabase().peel(ref);
ObjectId refObjectId;
if (ref.isPeeled() && ref.getPeeledObjectId() != null) {
refObjectId = ref.getPeeledObjectId();
} else {
refObjectId = ref.getObjectId();
}
if (refObjectId.equals(rev)) {
Ref peeledRef = repository.getRefDatabase().peel(ref);
ObjectId targetObjectId = peeledRef.getPeeledObjectId() != null
? peeledRef.getPeeledObjectId()
: peeledRef.getObjectId();
if (targetObjectId.equals(revObjectId)) {
String tagName = ref.getName().replaceFirst("^" + R_TAGS, "");
tagNames.add(tagName);
}
System.out.println("");
}
return tagNames;
}
Expand Down

0 comments on commit 6eaaa00

Please sign in to comment.