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>
tags/v0.9.1
Shawn O. Pearce 14 years ago
parent
commit
599c0ce745
1 changed files with 14 additions and 9 deletions
  1. 14
    9
      org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java

+ 14
- 9
org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java View File

@@ -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<Ref> {
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;
}
}

Loading…
Cancel
Save