diff --git a/build.gradle b/build.gradle index 94202ca..4059566 100644 --- a/build.gradle +++ b/build.gradle @@ -21,9 +21,9 @@ dependencies { implementation 'org.eclipse.jgit:org.eclipse.jgit:5.13.1.202206130422-r' implementation 'org.gitlab:java-gitlab-api:4.1.1' - testImplementation 'org.slf4j:slf4j-simple:1.7.30' // Same as JGit + testImplementation 'org.slf4j:slf4j-simple:1.8.0-beta2' // Same as JGit testImplementation 'junit:junit:4.13.2' - testImplementation 'org.assertj:assertj-core:3.23.1' + testImplementation 'org.assertj:assertj-core:3.24.2' testImplementation 'com.approvaltests:approvaltests:18.5.0' - testImplementation 'org.mockito:mockito-core:4.11.0' + testImplementation 'org.mockito:mockito-core:5.2.0' } diff --git a/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java b/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java index bf88173..5a8de5c 100644 --- a/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java +++ b/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java @@ -21,6 +21,7 @@ import java.util.TreeMap; import java.util.TreeSet; import java.util.stream.Collectors; + import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.LogCommand; import org.eclipse.jgit.lib.AnyObjectId; @@ -33,6 +34,7 @@ import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import se.bjurr.gitchangelog.api.GitChangelogApiConstants; import se.bjurr.gitchangelog.api.exceptions.GitChangelogRepositoryException; import se.bjurr.gitchangelog.internal.git.model.GitCommit; @@ -437,44 +439,36 @@ private void populateComitPerTag( final RevCommit thisCommit = this.revWalk.lookupCommit(to); this.revWalk.parseHeaders(thisCommit); - final PriorityQueue moreWork = - new PriorityQueue<>( - this.populateCommitPerTag( - from, - to, - commitsPerTag, - tagPerCommitHash, - tagPerCommitsHash, - datePerTag, - startingTagName)); - - while (!moreWork.isEmpty()) { + final PriorityQueue moreWork = new PriorityQueue<>(); + moreWork.add(new TraversalWork(to, startingTagName)); + do { final TraversalWork next = moreWork.remove(); - moreWork.addAll( - this.populateCommitPerTag( - from, - next.getTo(), - commitsPerTag, - tagPerCommitHash, - tagPerCommitsHash, - datePerTag, - next.getCurrentTagName())); + this.populateCommitPerTag( + from, + next.getTo(), + commitsPerTag, + tagPerCommitHash, + tagPerCommitsHash, + datePerTag, + next.getCurrentTagName(), + moreWork); LOG.debug("Work left: " + moreWork.size()); - } + } while (!moreWork.isEmpty()); } - private Set populateCommitPerTag( + private void populateCommitPerTag( final RevCommit from, final RevCommit to, final Map> commitsPerTagName, final Map tagPerCommitHash, final Map tagPerCommitsHash, final Map datePerTag, - String currentTagName) + String currentTagName, + final PriorityQueue moreWork) throws Exception { final String thisCommitHash = to.getName(); if (this.isMappedToAnotherTag(tagPerCommitsHash, thisCommitHash)) { - return new TreeSet<>(); + return; } if (this.thisIsANewTag(tagPerCommitHash, thisCommitHash)) { currentTagName = this.getTagName(tagPerCommitHash, thisCommitHash); @@ -486,16 +480,20 @@ private Set populateCommitPerTag( this.noteThatTheCommitWasMapped(tagPerCommitsHash, currentTagName, thisCommitHash); } if (this.notFirstIncludedCommit(from, to)) { - final Set work = new TreeSet<>(); for (final RevCommit parent : to.getParents()) { if (this.shouldInclude(parent)) { this.revWalk.parseHeaders(parent); - work.add(new TraversalWork(parent, currentTagName)); + final TraversalWork work = new TraversalWork(parent, currentTagName); + if (moreWork.contains(work)) { + LOG.info("Removing "+work.getTo().getName()); + moreWork.remove(work); // Remove work added from reference by a newer commit + } + LOG.info("Adding "+work.getTo().getName() + " tag: "+work.getCurrentTagName()); + moreWork.add(work); // Add work from this older reference } } - return work; } - return new TreeSet<>(); + return; } private boolean shouldInclude(final RevCommit candidate) throws Exception { diff --git a/src/main/java/se/bjurr/gitchangelog/internal/git/TraversalWork.java b/src/main/java/se/bjurr/gitchangelog/internal/git/TraversalWork.java index 8e5f12f..ccea986 100644 --- a/src/main/java/se/bjurr/gitchangelog/internal/git/TraversalWork.java +++ b/src/main/java/se/bjurr/gitchangelog/internal/git/TraversalWork.java @@ -23,7 +23,6 @@ public RevCommit getTo() { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((this.currentTagName == null) ? 0 : this.currentTagName.hashCode()); result = prime * result + ((this.to == null) ? 0 : this.to.hashCode()); return result; } @@ -40,13 +39,6 @@ public boolean equals(final Object obj) { return false; } final TraversalWork other = (TraversalWork) obj; - if (this.currentTagName == null) { - if (other.currentTagName != null) { - return false; - } - } else if (!this.currentTagName.equals(other.currentTagName)) { - return false; - } if (this.to == null) { if (other.to != null) { return false; @@ -62,8 +54,7 @@ public int compareTo(final TraversalWork o) { final int otherCommitTime = o.getTo().getCommitTime(); final int compareTo = this.compareTo(this.to.getCommitTime(), otherCommitTime); if (compareTo == 0) { - return (this.to.getName() + this.currentTagName) - .compareTo(o.getTo().getName() + o.getCurrentTagName()); + return (this.to.getName()).compareTo(o.getTo().getName()); } return compareTo; } diff --git a/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testThatCommitsWithoutIssueCanBeIgnoredTagsIssuesCommits.approved.txt b/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testThatCommitsWithoutIssueCanBeIgnoredTagsIssuesCommits.approved.txt index ef3df01..45c947b 100644 --- a/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testThatCommitsWithoutIssueCanBeIgnoredTagsIssuesCommits.approved.txt +++ b/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testThatCommitsWithoutIssueCanBeIgnoredTagsIssuesCommits.approved.txt @@ -136,7 +136,6 @@ context: ], "tags": [ { - "annotation": "A tag in test-feature\n", "authors": [ { "commits": [ @@ -269,9 +268,9 @@ context: "type": "CUSTOM" } ], - "name": "tag-in-test-feature", - "tagTime": "2016-04-06 15:13:04", - "tagTimeLong": 1459955584000, + "name": "test", + "tagTime": "2016-04-06 18:40:51", + "tagTimeLong": 1459968051000, "hasTagTime": true }, {