From 864091d982a32050fa6dc3d5969b51b94f0e488c Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 3 Dec 2010 13:19:15 -0800 Subject: [PATCH] Ensure stable tag sort in PlotWalk Because tags are more interesting here than local or remote branch heads, tags get sorted earlier in the array than heads or remotes do. Bug: 324939 Change-Id: Ifc3863461654df7f34fdecbd2abe1f4b5d2ffb8e Signed-off-by: Shawn O. Pearce CC: Mathias Kinzler CC: Stefan Lay --- .../org/eclipse/jgit/revplot/PlotWalk.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java index c69e66cb8c..b4c90c54d3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java @@ -44,6 +44,10 @@ package org.eclipse.jgit.revplot; +import static org.eclipse.jgit.lib.Constants.R_HEADS; +import static org.eclipse.jgit.lib.Constants.R_REMOTES; +import static org.eclipse.jgit.lib.Constants.R_TAGS; + import java.io.IOException; import java.util.Arrays; import java.util.Collection; @@ -131,11 +135,14 @@ public class PlotWalk extends RevWalk { return -1; if (t1 < t2) return 1; - return 0; } catch (IOException e) { // ignore - return 0; } + + int cmp = kind(o1) - kind(o2); + if (cmp == 0) + cmp = o1.getName().compareTo(o2.getName()); + return cmp; } long timeof(RevObject o) { @@ -148,5 +155,15 @@ public class PlotWalk extends RevWalk { } return 0; } + + int kind(Ref r) { + if (r.getName().startsWith(R_TAGS)) + return 0; + if (r.getName().startsWith(R_HEADS)) + return 1; + if (r.getName().startsWith(R_REMOTES)) + return 2; + return 3; + } } } -- 2.39.5