Browse Source

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 <spearce@spearce.org>
stable-0.9
Shawn O. Pearce 15 years ago
parent
commit
599c0ce745
  1. 23
      org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java

23
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.JGitText;
import org.eclipse.jgit.lib.AnyObjectId; 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.Ref;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.Tag;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevSort; import org.eclipse.jgit.revwalk.RevSort;
import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
/** Specialized RevWalk for visualization of a commit graph. */ /** Specialized RevWalk for visualization of a commit graph. */
@ -115,8 +116,8 @@ public class PlotWalk extends RevWalk {
class PlotRefComparator implements Comparator<Ref> { class PlotRefComparator implements Comparator<Ref> {
public int compare(Ref o1, Ref o2) { public int compare(Ref o1, Ref o2) {
try { try {
Object obj1 = getRepository().mapObject(o1.getObjectId(), o1.getName()); RevObject obj1 = parseAny(o1.getObjectId());
Object obj2 = getRepository().mapObject(o2.getObjectId(), o2.getName()); RevObject obj2 = parseAny(o2.getObjectId());
long t1 = timeof(obj1); long t1 = timeof(obj1);
long t2 = timeof(obj2); long t2 = timeof(obj2);
if (t1 > t2) if (t1 > t2)
@ -129,11 +130,15 @@ public class PlotWalk extends RevWalk {
return 0; return 0;
} }
} }
long timeof(Object o) {
if (o instanceof Commit) long timeof(RevObject o) {
return ((Commit)o).getCommitter().getWhen().getTime(); if (o instanceof RevCommit)
if (o instanceof Tag) return ((RevCommit) o).getCommitTime();
return ((Tag)o).getTagger().getWhen().getTime(); if (o instanceof RevTag) {
RevTag tag = (RevTag) o;
PersonIdent who = tag.getTaggerIdent();
return who != null ? who.getWhen().getTime() : 0;
}
return 0; return 0;
} }
} }

Loading…
Cancel
Save