From 7d5e1f8497966b78b4c810904baef320a4ea6d69 Mon Sep 17 00:00:00 2001 From: Gustaf Lundh Date: Mon, 24 Mar 2014 18:05:32 +0100 Subject: [PATCH] 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 Signed-off-by: Sven Selberg --- org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java index e92035359..b3c4cced7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java @@ -1,6 +1,7 @@ /* * Copyright (C) 2007, Robin Rosenberg * Copyright (C) 2008, Shawn O. Pearce + * Copyright (C) 2014, Gustaf Lundh * 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 { 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;