From 599c0ce745ab0322fc110a374bacf3c5a142da7b Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 14 Jun 2010 18:51:09 -0700 Subject: [PATCH] Use RevTag/RevCommit to sort in a PlotWalk We already have these objects parsed and cached in our object pool. We shouldn't be looking them up via the legacy mapObject API, but instead can use the pool and the faster parsing routines available through the RevWalk that we extend. While we are here fixing the code, lets also correct the tag date sorting to accept tags that have no tagger identity, because they were created before Git knew how to store that field. Change-Id: Id49a11f6d9c050c82b876e5e11058840c894b2d7 Signed-off-by: Shawn O. Pearce --- .../org/eclipse/jgit/revplot/PlotWalk.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 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 6b4ed80e1..476592f5d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java @@ -53,12 +53,13 @@ import java.util.Set; import org.eclipse.jgit.JGitText; import org.eclipse.jgit.lib.AnyObjectId; -import org.eclipse.jgit.lib.Commit; +import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.lib.Tag; import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevObject; import org.eclipse.jgit.revwalk.RevSort; +import org.eclipse.jgit.revwalk.RevTag; import org.eclipse.jgit.revwalk.RevWalk; /** Specialized RevWalk for visualization of a commit graph. */ @@ -115,8 +116,8 @@ public class PlotWalk extends RevWalk { class PlotRefComparator implements Comparator { public int compare(Ref o1, Ref o2) { try { - Object obj1 = getRepository().mapObject(o1.getObjectId(), o1.getName()); - Object obj2 = getRepository().mapObject(o2.getObjectId(), o2.getName()); + RevObject obj1 = parseAny(o1.getObjectId()); + RevObject obj2 = parseAny(o2.getObjectId()); long t1 = timeof(obj1); long t2 = timeof(obj2); if (t1 > t2) @@ -129,11 +130,15 @@ public class PlotWalk extends RevWalk { return 0; } } - long timeof(Object o) { - if (o instanceof Commit) - return ((Commit)o).getCommitter().getWhen().getTime(); - if (o instanceof Tag) - return ((Tag)o).getTagger().getWhen().getTime(); + + long timeof(RevObject o) { + if (o instanceof RevCommit) + return ((RevCommit) o).getCommitTime(); + if (o instanceof RevTag) { + RevTag tag = (RevTag) o; + PersonIdent who = tag.getTaggerIdent(); + return who != null ? who.getWhen().getTime() : 0; + } return 0; } }