Skip to content

Commit

Permalink
fix: avoiding stuck execution (refs #95)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Mar 12, 2023
1 parent 313bef2 commit 0f5ec29
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 46 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
56 changes: 27 additions & 29 deletions src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -437,44 +439,36 @@ private void populateComitPerTag(
final RevCommit thisCommit = this.revWalk.lookupCommit(to);
this.revWalk.parseHeaders(thisCommit);

final PriorityQueue<TraversalWork> moreWork =
new PriorityQueue<>(
this.populateCommitPerTag(
from,
to,
commitsPerTag,
tagPerCommitHash,
tagPerCommitsHash,
datePerTag,
startingTagName));

while (!moreWork.isEmpty()) {
final PriorityQueue<TraversalWork> 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<TraversalWork> populateCommitPerTag(
private void populateCommitPerTag(
final RevCommit from,
final RevCommit to,
final Map<String, Set<GitCommit>> commitsPerTagName,
final Map<String, Ref> tagPerCommitHash,
final Map<String, String> tagPerCommitsHash,
final Map<String, Date> datePerTag,
String currentTagName)
String currentTagName,
final PriorityQueue<TraversalWork> 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);
Expand All @@ -486,16 +480,20 @@ private Set<TraversalWork> populateCommitPerTag(
this.noteThatTheCommitWasMapped(tagPerCommitsHash, currentTagName, thisCommitHash);
}
if (this.notFirstIncludedCommit(from, to)) {
final Set<TraversalWork> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ context:
],
"tags": [
{
"annotation": "A tag in test-feature\n",
"authors": [
{
"commits": [
Expand Down Expand Up @@ -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
},
{
Expand Down

0 comments on commit 0f5ec29

Please sign in to comment.