]> source.dussan.org Git - jgit.git/commitdiff
Fixed RevWalk.isMergedInto() returning wrong results 18/23818/1
authorGustaf Lundh <gustaf.lundh@sonymobile.com>
Mon, 24 Mar 2014 17:05:32 +0000 (18:05 +0100)
committerGustaf Lundh <gustaf.lundh@sonymobile.com>
Mon, 24 Mar 2014 17:41:48 +0000 (18:41 +0100)
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>
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java

index e920353592f5f6cd4728704c94b34ff8b83bef55..b3c4cced7444e8d61c1e1993b19c54a9da03cd82 100644 (file)
@@ -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;