The Unified and Autonomous Development Platform
Make PullRequest.getSortedUpdates() returning updates in ascending order.
robin shine81817e50b9bc
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.javaindex 5b59c2ba12..edc8abfe81 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java@@ -15,6 +15,7 @@ import com.pmease.commons.util.Triple;import com.pmease.commons.util.diff.DiffUtils;import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.PullRequestComment;+import com.pmease.gitplex.core.model.PullRequestUpdate;import com.pmease.gitplex.core.model.Repository;@SuppressWarnings("serial")@@ -27,8 +28,8 @@ public class ChangeComments implements Serializable {public ChangeComments(PullRequest request, RevAwareChange change) {List<String> commits = new ArrayList<>();commits.add(request.getBaseCommit());- for (int i=request.getSortedUpdates().size()-1; i>=0; i--)- commits.add(request.getSortedUpdates().get(i).getHeadCommit());+ for (PullRequestUpdate update: request.getSortedUpdates())+ commits.add(update.getHeadCommit());Map<String, Map<String, List<InlineComment>>> comments = new HashMap<>();Map<BlobInfo, List<String>> blobs = new HashMap<>();diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.javaindex 101cbdf4b6..d0882bf84b 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java@@ -332,17 +332,16 @@ public class PullRequest extends AbstractEntity {}/**- * Get list of reversely sorted updates.+ * Get list of sorted updates.** @return- * list of sorted updates ordered by id reversely+ * list of sorted updates ordered by id*/public List<PullRequestUpdate> getSortedUpdates() {if (sortedUpdates == null) {Preconditions.checkState(getUpdates().size() >= 1);sortedUpdates = new ArrayList<PullRequestUpdate>(getUpdates());Collections.sort(sortedUpdates);- Collections.reverse(sortedUpdates);}return sortedUpdates;}@@ -359,12 +358,12 @@ public class PullRequest extends AbstractEntity {effectiveUpdates = new ArrayList<PullRequestUpdate>();Git git = getTarget().getRepository().git();- for (PullRequestUpdate update: getSortedUpdates()) {- if (!git.isAncestor(update.getHeadCommit(), getTarget().getHeadCommit())) {+ for (int i=getSortedUpdates().size()-1; i>=0; i--) {+ PullRequestUpdate update = getSortedUpdates().get(i);+ if (!git.isAncestor(update.getHeadCommit(), getTarget().getHeadCommit()))effectiveUpdates.add(update);- } else {+ elsebreak;- }}Preconditions.checkState(!effectiveUpdates.isEmpty());@@ -373,7 +372,7 @@ public class PullRequest extends AbstractEntity {}public PullRequestUpdate getLatestUpdate() {- return getSortedUpdates().get(0);+ return getSortedUpdates().get(getSortedUpdates().size()-1);}public Collection<String> findTouchedFiles() {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.javaindex adc823385a..62714e5191 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestUpdate.java@@ -220,8 +220,8 @@ public class PullRequestUpdate extends AbstractEntity {PullRequest request = getRequest();int index = request.getSortedUpdates().indexOf(this);- if (index < request.getSortedUpdates().size()-1)- baseCommit = request.getSortedUpdates().get(index+1).getHeadCommit();+ if (index > 0)+ baseCommit = request.getSortedUpdates().get(index-1).getHeadCommit();elsebaseCommit = request.getBaseCommit();}diff --git a/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestUpdateTest.java b/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestUpdateTest.javaindex e6859a992f..fdc2979b50 100644--- a/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestUpdateTest.java+++ b/gitplex.core/src/test/java/com/pmease/gitplex/core/model/PullRequestUpdateTest.java@@ -69,7 +69,7 @@ public class PullRequestUpdateTest extends AbstractGitTest {target.setHeadCommit(bareGit.parseRevision("master", true));Assert.assertEquals(bareGit.showRevision("dev~1").getHash(), request.getLatestUpdate().getReferentialCommit());- Assert.assertEquals(bareGit.showRevision("master~1").getHash(), request.getSortedUpdates().get(1).getReferentialCommit());+ Assert.assertEquals(bareGit.showRevision("master~1").getHash(), request.getSortedUpdates().get(0).getReferentialCommit());}@Test@@ -116,7 +116,7 @@ public class PullRequestUpdateTest extends AbstractGitTest {Commit referentialCommit = bareGit.showRevision(request.getLatestUpdate().getReferentialCommit());Assert.assertTrue(referentialCommit.getParentHashes().contains(bareGit.showRevision("master").getHash()));Assert.assertTrue(referentialCommit.getParentHashes().contains(bareGit.showRevision("dev~2").getHash()));- Assert.assertEquals(bareGit.showRevision("master~1").getHash(), request.getSortedUpdates().get(1).getReferentialCommit());+ Assert.assertEquals(bareGit.showRevision("master~1").getHash(), request.getSortedUpdates().get(0).getReferentialCommit());}@Testdiff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.javaindex 691c629a8f..3618190136 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestComparePage.java@@ -19,8 +19,6 @@ import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;import org.apache.wicket.ajax.markup.html.AjaxLink;import org.apache.wicket.event.IEvent;import org.apache.wicket.markup.ComponentTag;-import org.apache.wicket.markup.head.IHeaderResponse;-import org.apache.wicket.markup.head.OnDomReadyHeaderItem;import org.apache.wicket.markup.html.WebMarkupContainer;import org.apache.wicket.markup.html.basic.Label;import org.apache.wicket.markup.html.form.CheckBox;@@ -134,9 +132,9 @@ public class RequestComparePage extends RequestDetailPage implements InlineCommegetRepository().git().showRevision(request.getBaseCommit()).getSubject());choices.put(request.getBaseCommit(), description);- for (int i=request.getSortedUpdates().size()-1; i>=0; i--) {+ for (int i=0; i<request.getSortedUpdates().size(); i++) {PullRequestUpdate update = request.getSortedUpdates().get(i);- int updateNo = request.getSortedUpdates().size()-i;+ int updateNo = i+1;name = "Head of Update #" + updateNo;String commitHash = update.getHeadCommit();if (commitHash.equals(concernedCommit))@@ -420,7 +418,7 @@ public class RequestComparePage extends RequestDetailPage implements InlineCommePullRequestUpdate update = getPullRequest().getSortedUpdates().get(i);final String baseCommit = update.getBaseCommit();final String headCommit = update.getHeadCommit();- int index = getPullRequest().getSortedUpdates().size()-i;+ int index = i+1;String oldLabel;if (index > 1)oldLabel = "Update #" + (index-1);@@ -685,7 +683,8 @@ public class RequestComparePage extends RequestDetailPage implements InlineCommesetOutputMarkupId(true);- IModel<List<Map.Entry<String, CommitDescription>>> model = new LoadableDetachableModel<List<Map.Entry<String, CommitDescription>>>() {+ IModel<List<Map.Entry<String, CommitDescription>>> model =+ new LoadableDetachableModel<List<Map.Entry<String, CommitDescription>>>() {@Overrideprotected List<Entry<String, CommitDescription>> load() {@@ -730,17 +729,6 @@ public class RequestComparePage extends RequestDetailPage implements InlineComme});}- @Override- public void renderHead(IHeaderResponse response) {- super.renderHead(response);- String script = String.format(""- + "$('#%s').closest('.dropdown-panel').on('show', function() {"- + " var $ul = $(this).find('ul');"- + " $ul.scrollTop($ul[0].scrollHeight);"- + "});", getMarkupId());- response.render(OnDomReadyHeaderItem.forScript(script));- }-}private class BlobLink extends AjaxLink<Void> {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.javaindex 7c67a2ae1f..665353fe48 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/info/pullrequest/RequestUpdatesPage.java@@ -54,9 +54,7 @@ public class RequestUpdatesPage extends RequestDetailPage {@Overridepublic List<PullRequestUpdate> load() {- List<PullRequestUpdate> updates = new ArrayList<>(getPullRequest().getSortedUpdates());- Collections.reverse(updates);- return updates;+ return getPullRequest().getSortedUpdates();}}) {@@ -67,7 +65,7 @@ public class RequestUpdatesPage extends RequestDetailPage {updateItem.add(new UserLink("name", new UserModel(update.getUser()), AvatarMode.NAME));List<PullRequestUpdate> updates = update.getRequest().getSortedUpdates();- int updateNo = updates.size() - updates.indexOf(update);+ int updateNo = updates.indexOf(update) + 1;updateItem.add(new Label("updateNo", updateNo));PageParameters params = RequestComparePage.paramsOf(update.getRequest(), update.getBaseCommit(), update.getHeadCommit(), null, null);