Skip to content

Commit 0f5ec29

Browse files
committed
fix: avoiding stuck execution (refs #95)
1 parent 313bef2 commit 0f5ec29

File tree

4 files changed

+34
-46
lines changed

4 files changed

+34
-46
lines changed

Diff for: build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ dependencies {
2121
implementation 'org.eclipse.jgit:org.eclipse.jgit:5.13.1.202206130422-r'
2222
implementation 'org.gitlab:java-gitlab-api:4.1.1'
2323

24-
testImplementation 'org.slf4j:slf4j-simple:1.7.30' // Same as JGit
24+
testImplementation 'org.slf4j:slf4j-simple:1.8.0-beta2' // Same as JGit
2525
testImplementation 'junit:junit:4.13.2'
26-
testImplementation 'org.assertj:assertj-core:3.23.1'
26+
testImplementation 'org.assertj:assertj-core:3.24.2'
2727
testImplementation 'com.approvaltests:approvaltests:18.5.0'
28-
testImplementation 'org.mockito:mockito-core:4.11.0'
28+
testImplementation 'org.mockito:mockito-core:5.2.0'
2929
}

Diff for: src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java

+27-29
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.TreeMap;
2222
import java.util.TreeSet;
2323
import java.util.stream.Collectors;
24+
2425
import org.eclipse.jgit.api.Git;
2526
import org.eclipse.jgit.api.LogCommand;
2627
import org.eclipse.jgit.lib.AnyObjectId;
@@ -33,6 +34,7 @@
3334
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
3435
import org.slf4j.Logger;
3536
import org.slf4j.LoggerFactory;
37+
3638
import se.bjurr.gitchangelog.api.GitChangelogApiConstants;
3739
import se.bjurr.gitchangelog.api.exceptions.GitChangelogRepositoryException;
3840
import se.bjurr.gitchangelog.internal.git.model.GitCommit;
@@ -437,44 +439,36 @@ private void populateComitPerTag(
437439
final RevCommit thisCommit = this.revWalk.lookupCommit(to);
438440
this.revWalk.parseHeaders(thisCommit);
439441

440-
final PriorityQueue<TraversalWork> moreWork =
441-
new PriorityQueue<>(
442-
this.populateCommitPerTag(
443-
from,
444-
to,
445-
commitsPerTag,
446-
tagPerCommitHash,
447-
tagPerCommitsHash,
448-
datePerTag,
449-
startingTagName));
450-
451-
while (!moreWork.isEmpty()) {
442+
final PriorityQueue<TraversalWork> moreWork = new PriorityQueue<>();
443+
moreWork.add(new TraversalWork(to, startingTagName));
444+
do {
452445
final TraversalWork next = moreWork.remove();
453-
moreWork.addAll(
454-
this.populateCommitPerTag(
455-
from,
456-
next.getTo(),
457-
commitsPerTag,
458-
tagPerCommitHash,
459-
tagPerCommitsHash,
460-
datePerTag,
461-
next.getCurrentTagName()));
446+
this.populateCommitPerTag(
447+
from,
448+
next.getTo(),
449+
commitsPerTag,
450+
tagPerCommitHash,
451+
tagPerCommitsHash,
452+
datePerTag,
453+
next.getCurrentTagName(),
454+
moreWork);
462455
LOG.debug("Work left: " + moreWork.size());
463-
}
456+
} while (!moreWork.isEmpty());
464457
}
465458

466-
private Set<TraversalWork> populateCommitPerTag(
459+
private void populateCommitPerTag(
467460
final RevCommit from,
468461
final RevCommit to,
469462
final Map<String, Set<GitCommit>> commitsPerTagName,
470463
final Map<String, Ref> tagPerCommitHash,
471464
final Map<String, String> tagPerCommitsHash,
472465
final Map<String, Date> datePerTag,
473-
String currentTagName)
466+
String currentTagName,
467+
final PriorityQueue<TraversalWork> moreWork)
474468
throws Exception {
475469
final String thisCommitHash = to.getName();
476470
if (this.isMappedToAnotherTag(tagPerCommitsHash, thisCommitHash)) {
477-
return new TreeSet<>();
471+
return;
478472
}
479473
if (this.thisIsANewTag(tagPerCommitHash, thisCommitHash)) {
480474
currentTagName = this.getTagName(tagPerCommitHash, thisCommitHash);
@@ -486,16 +480,20 @@ private Set<TraversalWork> populateCommitPerTag(
486480
this.noteThatTheCommitWasMapped(tagPerCommitsHash, currentTagName, thisCommitHash);
487481
}
488482
if (this.notFirstIncludedCommit(from, to)) {
489-
final Set<TraversalWork> work = new TreeSet<>();
490483
for (final RevCommit parent : to.getParents()) {
491484
if (this.shouldInclude(parent)) {
492485
this.revWalk.parseHeaders(parent);
493-
work.add(new TraversalWork(parent, currentTagName));
486+
final TraversalWork work = new TraversalWork(parent, currentTagName);
487+
if (moreWork.contains(work)) {
488+
LOG.info("Removing "+work.getTo().getName());
489+
moreWork.remove(work); // Remove work added from reference by a newer commit
490+
}
491+
LOG.info("Adding "+work.getTo().getName() + " tag: "+work.getCurrentTagName());
492+
moreWork.add(work); // Add work from this older reference
494493
}
495494
}
496-
return work;
497495
}
498-
return new TreeSet<>();
496+
return;
499497
}
500498

501499
private boolean shouldInclude(final RevCommit candidate) throws Exception {

Diff for: src/main/java/se/bjurr/gitchangelog/internal/git/TraversalWork.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public RevCommit getTo() {
2323
public int hashCode() {
2424
final int prime = 31;
2525
int result = 1;
26-
result = prime * result + ((this.currentTagName == null) ? 0 : this.currentTagName.hashCode());
2726
result = prime * result + ((this.to == null) ? 0 : this.to.hashCode());
2827
return result;
2928
}
@@ -40,13 +39,6 @@ public boolean equals(final Object obj) {
4039
return false;
4140
}
4241
final TraversalWork other = (TraversalWork) obj;
43-
if (this.currentTagName == null) {
44-
if (other.currentTagName != null) {
45-
return false;
46-
}
47-
} else if (!this.currentTagName.equals(other.currentTagName)) {
48-
return false;
49-
}
5042
if (this.to == null) {
5143
if (other.to != null) {
5244
return false;
@@ -62,8 +54,7 @@ public int compareTo(final TraversalWork o) {
6254
final int otherCommitTime = o.getTo().getCommitTime();
6355
final int compareTo = this.compareTo(this.to.getCommitTime(), otherCommitTime);
6456
if (compareTo == 0) {
65-
return (this.to.getName() + this.currentTagName)
66-
.compareTo(o.getTo().getName() + o.getCurrentTagName());
57+
return (this.to.getName()).compareTo(o.getTo().getName());
6758
}
6859
return compareTo;
6960
}

Diff for: src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testThatCommitsWithoutIssueCanBeIgnoredTagsIssuesCommits.approved.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ context:
136136
],
137137
"tags": [
138138
{
139-
"annotation": "A tag in test-feature\n",
140139
"authors": [
141140
{
142141
"commits": [
@@ -269,9 +268,9 @@ context:
269268
"type": "CUSTOM"
270269
}
271270
],
272-
"name": "tag-in-test-feature",
273-
"tagTime": "2016-04-06 15:13:04",
274-
"tagTimeLong": 1459955584000,
271+
"name": "test",
272+
"tagTime": "2016-04-06 18:40:51",
273+
"tagTimeLong": 1459968051000,
275274
"hasTagTime": true
276275
},
277276
{

0 commit comments

Comments
 (0)