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>
This commit is contained in:
parent
e1b312b5f7
commit
599c0ce745
|
@ -53,12 +53,13 @@
|
|||
|
||||
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 @@ protected Ref[] getTags(final AnyObjectId commitId) {
|
|||
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 int compare(Ref o1, Ref o2) {
|
|||
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…
Reference in New Issue