summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorAdithya Chakilam <achakila@codeaurora.org>2021-01-29 19:35:04 -0600
committerMatthias Sohn <matthias.sohn@sap.com>2021-02-07 06:09:48 -0500
commitc7685003d8fb11e39234866fd43b82b7ba883a2f (patch)
treec70c61b3eb86661cddc4220099a86ddde834315f /org.eclipse.jgit
parent3259a960217f1dd44c46007a545f473bd575f951 (diff)
downloadjgit-c7685003d8fb11e39234866fd43b82b7ba883a2f.tar.gz
jgit-c7685003d8fb11e39234866fd43b82b7ba883a2f.zip
Fix DateRevQueue tie breaks with more than 2 elements
DateRevQueue is expected to give out the commits that have higher commit time. But in case of tie(same commit time), it should give the commit that is inserted first. This is inferred from the testInsertTie test case written for DateRevQueue. Also that test case, right now uses just two commits which caused it not to fail with the current implementation, so added another commit to make the test more robust. By fixing the DateRevQueue, we would also match the behaviour of LogCommand.addRange(c1,c2) with git log c1..c2. A test case for the same is added to show that current behaviour is not the expected one. By fixing addRange(), the order in which commits are applied during a rebase is altered. Rebase logic should have never depended upon LogCommand.addRange() since the intended order of addRange() is not the order a rebase should use. So, modify the RebaseCommand to use RevWalk directly with TopoNonIntermixSortGenerator. Add a new LogCommandTest.addRangeWithMerge() test case which creates commits in the following order: A - B - C - M \ / -D- Using git 2.30.0, git log B..M outputs: M C D LogCommand.addRange(B, M) without this fix outputs: M D C LogCommand.addRange(B, M) with this fix outputs: M C D Change-Id: I30cc3ba6c97f0960f64e9e021df96ff276f63db7 Signed-off-by: Adithya Chakilam <achakila@codeaurora.org>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java21
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java2
2 files changed, 14 insertions, 9 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
index 6678af163a..836175dcea 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
@@ -67,6 +67,7 @@ import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevSort;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.revwalk.filter.RevFilter;
import org.eclipse.jgit.submodule.SubmoduleWalk.IgnoreSubmoduleMode;
@@ -1137,15 +1138,19 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
private List<RevCommit> calculatePickList(RevCommit headCommit)
throws GitAPIException, NoHeadException, IOException {
- Iterable<RevCommit> commitsToUse;
- try (Git git = new Git(repo)) {
- LogCommand cmd = git.log().addRange(upstreamCommit, headCommit);
- commitsToUse = cmd.call();
- }
List<RevCommit> cherryPickList = new ArrayList<>();
- for (RevCommit commit : commitsToUse) {
- if (preserveMerges || commit.getParentCount() == 1)
- cherryPickList.add(commit);
+ try (RevWalk r = new RevWalk(repo)) {
+ r.sort(RevSort.TOPO_KEEP_BRANCH_TOGETHER, true);
+ r.sort(RevSort.COMMIT_TIME_DESC, true);
+ r.markUninteresting(r.lookupCommit(upstreamCommit));
+ r.markStart(r.lookupCommit(headCommit));
+ Iterator<RevCommit> commitsToUse = r.iterator();
+ while (commitsToUse.hasNext()) {
+ RevCommit commit = commitsToUse.next();
+ if (preserveMerges || commit.getParentCount() == 1) {
+ cherryPickList.add(commit);
+ }
+ }
}
Collections.reverse(cherryPickList);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java
index b875be9270..0cabf07057 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java
@@ -93,7 +93,7 @@ public class DateRevQueue extends AbstractRevQueue {
head = n;
} else {
Entry p = q.next;
- while (p != null && p.commit.commitTime > when) {
+ while (p != null && p.commit.commitTime >= when) {
q = p;
p = q.next;
}