Browse Source

Fixed RevWalk.isMergedInto() returning wrong results

Under certain circumstances isMergedInto() returned
false even though base is reachable from the tip.
This will hinder pushes and receives by falsely
detecting "non fast forward" merges.

      o---o---o---o---o
      /                 \
     /   o---o---A---o---M
    /   /
---2---1-

if M (tip) was compared to 1 (base), the method
isMergedInto() could still return false, since
two mergeBases will be detected and the return
statement will only look at one of them:

  return next() == base;

In most cases this would pass, but if "A" is
a commit with an old timestamp, the Generator
would walk down to "2" before completing the
walk pass "A" and first finding the other
merge base "1". In this case, the first call to
next() returns 2, which compared to base evaluates
as false.

This is fixed by iterating merge bases and
returning true if base is found among them.

Change-Id: If2ee1f4270f5ea4bee73ecb0e9c933f8234818da
Signed-off-by: Gustaf Lundh <gustaf.lundh@sonymobile.com>
Signed-off-by: Sven Selberg <sven.selberg@sonymobile.com>
stable-3.4
Gustaf Lundh 11 years ago
parent
commit
7d5e1f8497
  1. 7
      org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java

7
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java

@ -1,6 +1,7 @@
/*
* Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
* Copyright (C) 2014, Gustaf Lundh <gustaf.lundh@sonymobile.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@ -388,7 +389,11 @@ public class RevWalk implements Iterable<RevCommit> {
treeFilter = TreeFilter.ALL;
markStart(tip);
markStart(base);
return next() == base;
RevCommit mergeBase;
while ((mergeBase = next()) != null)
if (mergeBase == base)
return true;
return false;
} finally {
filter = oldRF;
treeFilter = oldTF;

Loading…
Cancel
Save