]> source.dussan.org Git - jgit.git/commitdiff
Fix tag sorting in PlotWalk 92/1192/1
authorShawn O. Pearce <spearce@spearce.org>
Wed, 28 Jul 2010 18:44:00 +0000 (11:44 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Wed, 28 Jul 2010 18:51:17 +0000 (11:51 -0700)
By deferring tag sorting until the commit is produced by the walker
we can avoid an infinite loop that was triggered by trying to sort
tags while allocating a commit.  This also avoids needing to look
at commits which aren't going to be produced in the result.

Bug: 321103
Change-Id: I25acc739db2ec0221a50b72c2d2aa618a9a75f37
Reviewed-by: Mathias Kinzler <mathias.kinzler@sap.com>
Reviewed-by: Christian Halstrick <christian.halstrick@sap.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommit.java
org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java

index a068943fbcf9d7478bf06423d0d503428fc17e10..dc9e0321f53c269d5683c52a2e4c02d86d55b612 100644 (file)
@@ -65,19 +65,16 @@ public class PlotCommit<L extends PlotLane> extends RevCommit {
 
        PlotCommit[] children;
 
-       final Ref[] refs;
+       Ref[] refs;
 
        /**
         * Create a new commit.
         *
         * @param id
         *            the identity of this commit.
-        * @param tags
-        *            the tags associated with this commit, null for no tags
         */
-       protected PlotCommit(final AnyObjectId id, final Ref[] tags) {
+       protected PlotCommit(final AnyObjectId id) {
                super(id);
-               this.refs = tags;
                passingLanes = NO_LANES;
                children = NO_CHILDREN;
        }
index 666cb0287bed6de1e010a50b80490da609aa0d6d..c69e66cb8cb99125c3c1b3c6612dca7138717804 100644 (file)
 package org.eclipse.jgit.revplot;
 
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.Map;
 import java.util.Set;
 
 import org.eclipse.jgit.JGitText;
+import org.eclipse.jgit.errors.IncorrectObjectTypeException;
+import org.eclipse.jgit.errors.MissingObjectException;
 import org.eclipse.jgit.lib.AnyObjectId;
 import org.eclipse.jgit.lib.PersonIdent;
 import org.eclipse.jgit.lib.Ref;
@@ -93,23 +96,26 @@ public class PlotWalk extends RevWalk {
 
        @Override
        protected RevCommit createCommit(final AnyObjectId id) {
-               return new PlotCommit(id, getTags(id));
+               return new PlotCommit(id);
        }
 
-       /**
-        * @param commitId
-        * @return return the list of knows tags referring to this commit
-        */
-       protected Ref[] getTags(final AnyObjectId commitId) {
+       @Override
+       public RevCommit next() throws MissingObjectException,
+                       IncorrectObjectTypeException, IOException {
+               PlotCommit<?> pc = (PlotCommit) super.next();
+               if (pc != null)
+                       pc.refs = getTags(pc);
+               return pc;
+       }
+
+       private Ref[] getTags(final AnyObjectId commitId) {
                Collection<Ref> list = reverseRefMap.get(commitId);
                Ref[] tags;
                if (list == null)
                        tags = null;
                else {
                        tags = list.toArray(new Ref[list.size()]);
-                       // TODO hotfix, this results in a loop and consequently stack overflow
-                       // when opening the history view in EGit
-                       // Arrays.sort(tags, new PlotRefComparator());
+                       Arrays.sort(tags, new PlotRefComparator());
                }
                return tags;
        }