Skip to content

The Unified and Autonomous Development Platform

Always compare against merge-base in revision compare page in order to make comparison simpler

robin shineaa925fdfe098
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/DepotAndRevision.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/DepotAndRevision.java
index 5ca57c7aca..123c4ecc0b 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/DepotAndRevision.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/component/DepotAndRevision.java
@@ -1,150 +1,150 @@
-package com.pmease.gitplex.core.entity.component;
-
-import java.io.Serializable;
-
-import javax.annotation.Nullable;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.revwalk.RevCommit;
-
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.Depot;
-
-public class DepotAndRevision implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- public static final String SEPARATOR = ":";
-
- private final Long depotId;
-
- private final String revision;
-
- private transient Depot depot;
-
- public DepotAndRevision(Long depotId, String revision) {
- this.depotId = depotId;
- this.revision = revision;
- }
-
- public DepotAndRevision(Depot depot, String revision) {
- this.depotId = depot.getId();
- this.revision = revision;
-
- this.depot = depot;
- }
-
- public DepotAndRevision(String depotAndRevision) {
- this(Long.valueOf(StringUtils.substringBefore(depotAndRevision, SEPARATOR)),
- StringUtils.substringAfter(depotAndRevision, SEPARATOR));
- }
-
- public Long getDepotId() {
- return depotId;
- }
-
- public String getRevision() {
- return revision;
- }
-
- @Nullable
- public Ref getRef() {
- return getDepot().getRef(getRevision());
- }
-
- @Nullable
- public String getBranch() {
- Ref ref = getRef();
- if (ref != null && ref.getName().startsWith(Constants.R_HEADS))
- return ref.getName().substring(Constants.R_HEADS.length());
- else
- return null;
- }
-
- @Nullable
- public String getTag() {
- Ref ref = getRef();
- if (ref != null && ref.getName().startsWith(Constants.R_TAGS))
- return ref.getName().substring(Constants.R_TAGS.length());
- else
- return null;
- }
-
- @Nullable
- public ObjectId getObjectId(boolean mustExist) {
- return getDepot().getObjectId(normalizeRevision(), mustExist);
- }
-
- public ObjectId getObjectId() {
- return getObjectId(true);
- }
-
- public RevCommit getCommit(boolean mustExist) {
- return getDepot().getRevCommit(getObjectId(mustExist), mustExist);
- }
-
- public RevCommit getCommit() {
- return getCommit(true);
- }
-
- public String getObjectName(boolean mustExist) {
- ObjectId objectId = getObjectId(mustExist);
- return objectId!=null?objectId.name():null;
- }
-
- public String getObjectName() {
- return getObjectName(true);
- }
-
- public String getFQN() {
- return getDepot().getFQN() + SEPARATOR + revision;
- }
-
- public boolean isDefault() {
- return getDepot().getDefaultBranch().equals(getRevision());
- }
-
- public void delete() {
- getDepot().deleteBranch(getRevision());
- }
-
- public Depot getDepot() {
- if (depot == null)
- depot = GitPlex.getInstance(Dao.class).load(Depot.class, depotId);
- return depot;
- }
-
- protected String normalizeRevision() {
- return revision;
- }
-
- @Override
- public boolean equals(Object other) {
- if (!(other instanceof DepotAndRevision))
- return false;
- if (this == other)
- return true;
- DepotAndRevision otherDepotAndRevision = (DepotAndRevision) other;
- return new EqualsBuilder()
- .append(depotId, otherDepotAndRevision.depotId)
- .append(revision, otherDepotAndRevision.revision)
- .isEquals();
- }
-
- @Override
- public int hashCode() {
- return new HashCodeBuilder(17, 37).append(depotId).append(revision).toHashCode();
- }
-
- @Override
- public String toString() {
- return depotId + SEPARATOR + revision;
- }
-
-}
+package com.pmease.gitplex.core.entity.component;
+
+import java.io.Serializable;
+
+import javax.annotation.Nullable;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.revwalk.RevCommit;
+
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.manager.DepotManager;
+
+public class DepotAndRevision implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final String SEPARATOR = ":";
+
+ private final Long depotId;
+
+ private final String revision;
+
+ private transient Depot depot;
+
+ public DepotAndRevision(Long depotId, String revision) {
+ this.depotId = depotId;
+ this.revision = revision;
+ }
+
+ public DepotAndRevision(Depot depot, String revision) {
+ this.depotId = depot.getId();
+ this.revision = revision;
+
+ this.depot = depot;
+ }
+
+ public DepotAndRevision(String depotAndRevision) {
+ this(Long.valueOf(StringUtils.substringBefore(depotAndRevision, SEPARATOR)),
+ StringUtils.substringAfter(depotAndRevision, SEPARATOR));
+ }
+
+ public Long getDepotId() {
+ return depotId;
+ }
+
+ public String getRevision() {
+ return revision;
+ }
+
+ @Nullable
+ public Ref getRef() {
+ return getDepot().getRef(getRevision());
+ }
+
+ @Nullable
+ public String getBranch() {
+ Ref ref = getRef();
+ if (ref != null && ref.getName().startsWith(Constants.R_HEADS))
+ return ref.getName().substring(Constants.R_HEADS.length());
+ else
+ return null;
+ }
+
+ @Nullable
+ public String getTag() {
+ Ref ref = getRef();
+ if (ref != null && ref.getName().startsWith(Constants.R_TAGS))
+ return ref.getName().substring(Constants.R_TAGS.length());
+ else
+ return null;
+ }
+
+ @Nullable
+ public ObjectId getObjectId(boolean mustExist) {
+ return getDepot().getObjectId(normalizeRevision(), mustExist);
+ }
+
+ public ObjectId getObjectId() {
+ return getObjectId(true);
+ }
+
+ public RevCommit getCommit(boolean mustExist) {
+ return getDepot().getRevCommit(getObjectId(mustExist), mustExist);
+ }
+
+ public RevCommit getCommit() {
+ return getCommit(true);
+ }
+
+ public String getObjectName(boolean mustExist) {
+ ObjectId objectId = getObjectId(mustExist);
+ return objectId!=null?objectId.name():null;
+ }
+
+ public String getObjectName() {
+ return getObjectName(true);
+ }
+
+ public String getFQN() {
+ return getDepot().getFQN() + SEPARATOR + revision;
+ }
+
+ public boolean isDefault() {
+ return getDepot().getDefaultBranch().equals(getRevision());
+ }
+
+ public void delete() {
+ getDepot().deleteBranch(getRevision());
+ }
+
+ public Depot getDepot() {
+ if (depot == null)
+ depot = GitPlex.getInstance(DepotManager.class).load(depotId);
+ return depot;
+ }
+
+ protected String normalizeRevision() {
+ return revision;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof DepotAndRevision))
+ return false;
+ if (this == other)
+ return true;
+ DepotAndRevision otherDepotAndRevision = (DepotAndRevision) other;
+ return new EqualsBuilder()
+ .append(depotId, otherDepotAndRevision.depotId)
+ .append(revision, otherDepotAndRevision.revision)
+ .isEquals();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder(17, 37).append(depotId).append(revision).toHashCode();
+ }
+
+ @Override
+ public String toString() {
+ return depotId + SEPARATOR + revision;
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.html
index 51425ddedc..552b60e398 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.html
@@ -4,16 +4,13 @@
<div class="body">
<div class="revisions clearfix">
<div class="revision pull-left">
- <div class="clearfix">
+ <div>
<label class="pull-left">Left side</label>
- <input wicket:id="compareWithMergeBase" type="checkbox" class="pull-left"></input>
- <span class="pull-left">common ancestor</span>
- <a wicket:id="tooltip" class="pull-left"><i class="fa fa-question-circle"></i></a>
</div>
<div wicket:id="leftSide"></div>
</div>
<div class="action pull-left">
- <a wicket:id="swap" class="swap btn btn-default" title="Swap"><i class="fa fa-arrows-h"></i></a>
+ <a wicket:id="swap" class="swap btn btn-default" title="Swap"><i class="fa fa-exchange"></i></a>
</div>
<div class="revision pull-left">
<div>
@@ -30,8 +27,7 @@
No changes between left side and right side
</div>
<div wicket:id="leftAhead" class="alert alert-warning">
- Left side has new commits since the branching point, <a wicket:id="compareWithMergeBase">tick the common ancestor option</a>
- to compare right side against the original branching point
+ Left side is ahead of right side, <a wicket:id="swap">swap</a> the comparison to see the changes
</div>
<div>
<a wicket:id="createRequest" class="btn btn-primary">Create Pull Request</a>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java
index c0ea00ff56..98f2eea2c4 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java
@@ -9,12 +9,10 @@ import javax.annotation.Nullable;
import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
@@ -23,14 +21,12 @@ import org.apache.wicket.model.Model;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.CssResourceReference;
+import org.eclipse.jgit.lib.ObjectId;
-import com.google.common.collect.Lists;
import com.pmease.commons.git.Commit;
import com.pmease.commons.git.Git;
-import com.pmease.commons.git.command.LogCommand;
import com.pmease.commons.lang.diff.WhitespaceOption;
import com.pmease.commons.util.FileUtils;
-import com.pmease.commons.wicket.behavior.TooltipBehavior;
import com.pmease.commons.wicket.component.backtotop.BackToTop;
import com.pmease.commons.wicket.component.tabbable.AjaxActionTab;
import com.pmease.commons.wicket.component.tabbable.Tab;
@@ -58,8 +54,6 @@ public class RevisionComparePage extends DepotPage {
private static final String PARAM_RIGHT = "right";
- private static final String PARAM_COMPARE_WITH_MERGE_BASE = "compare-with-merge-base";
-
private static final String PARAM_WHITESPACE_OPTION = "whitespace-option";
private static final String PARAM_COMMENT = "comment";
@@ -80,11 +74,12 @@ public class RevisionComparePage extends DepotPage {
private HistoryState state = new HistoryState();
+ private ObjectId resolvedRightSideRevision;
+
public static PageParameters paramsOf(Depot depot, HistoryState state) {
PageParameters params = paramsOf(depot);
params.set(PARAM_LEFT, state.leftSide.toString());
params.set(PARAM_RIGHT, state.rightSide.toString());
- params.set(PARAM_COMPARE_WITH_MERGE_BASE, state.compareWithMergeBase);
if (state.whitespaceOption != WhitespaceOption.DEFAULT)
params.set(PARAM_WHITESPACE_OPTION, state.whitespaceOption.name());
if (state.pathFilter != null)
@@ -106,6 +101,7 @@ public class RevisionComparePage extends DepotPage {
} else {
state.rightSide = new DepotAndRevision(getDepot(), getDepot().getDefaultBranch());
}
+ resolvedRightSideRevision = state.rightSide.getObjectId();
str = params.get(PARAM_LEFT).toString();
if (str != null) {
@@ -114,8 +110,6 @@ public class RevisionComparePage extends DepotPage {
state.leftSide = new DepotAndRevision(getDepot(), getDepot().getDefaultBranch());
}
- state.compareWithMergeBase = params.get(PARAM_COMPARE_WITH_MERGE_BASE).toBoolean(false);
-
state.pathFilter = params.get(PARAM_PATH_FILTER).toString();
state.whitespaceOption = WhitespaceOption.of(params.get(PARAM_WHITESPACE_OPTION).toString());
@@ -157,17 +151,8 @@ public class RevisionComparePage extends DepotPage {
@Override
protected List<Commit> load() {
- Depot sourceDepot = state.leftSide.getDepot();
- LogCommand log = new LogCommand(sourceDepot.git().depotDir());
- List<Commit> commits;
- if (!state.compareWithMergeBase) {
- String revisions = state.leftSide.getRevision() + "..." + state.rightSide.getRevision();
- commits = log.revisions(Lists.newArrayList(revisions)).call();
- commits.add(sourceDepot.git().showRevision(mergeBaseModel.getObject()));
- } else {
- commits = sourceDepot.git().log(state.leftSide.getRevision(), state.rightSide.getRevision(), null, 0, 0, false);
- }
- return commits;
+ Depot rightDepot = state.rightSide.getDepot();
+ return rightDepot.git().log(mergeBaseModel.getObject(), state.rightSide.getRevision(), null, 0, 0, false);
}
};
@@ -187,26 +172,11 @@ public class RevisionComparePage extends DepotPage {
HistoryState state = new HistoryState(RevisionComparePage.this.state);
state.leftSide = new DepotAndRevision(depot, revision);
- PageParameters params = paramsOf(getDepot(), state);
+ PageParameters params = paramsOf(depot, state);
setResponsePage(RevisionComparePage.class, params);
}
});
- add(new CheckBox("compareWithMergeBase", Model.of(state.compareWithMergeBase)).add(new OnChangeAjaxBehavior() {
-
- @Override
- protected void onUpdate(AjaxRequestTarget target) {
- HistoryState state = new HistoryState(RevisionComparePage.this.state);
- state.compareWithMergeBase = !state.compareWithMergeBase;
-
- PageParameters params = RevisionComparePage.paramsOf(depotModel.getObject(), state);
- setResponsePage(RevisionComparePage.class, params);
- }
-
- }));
- String tooltip = "Check this to compare \"right side\" with common ancestor of left and right";
- add(new WebMarkupContainer("tooltip").add(new TooltipBehavior(Model.of(tooltip))));
-
add(new AffinalRevisionPicker("rightSide", state.rightSide.getDepotId(), state.rightSide.getRevision()) {
@Override
@@ -245,9 +215,7 @@ public class RevisionComparePage extends DepotPage {
protected void onConfigure() {
super.onConfigure();
- if (state.leftSide.getBranch()!=null
- && state.rightSide.getBranch()!=null
- && state.compareWithMergeBase) {
+ if (state.leftSide.getBranch()!=null && state.rightSide.getBranch()!=null) {
PullRequest request = requestModel.getObject();
setVisible(request == null && !mergeBaseModel.getObject().equals(state.rightSide.getCommit().name()));
} else {
@@ -263,12 +231,8 @@ public class RevisionComparePage extends DepotPage {
protected void onConfigure() {
super.onConfigure();
- if (state.compareWithMergeBase) {
- PullRequest request = requestModel.getObject();
- setVisible(request != null);
- } else {
- setVisible(false);
- }
+ PullRequest request = requestModel.getObject();
+ setVisible(request != null);
}
@Override
@@ -323,13 +287,14 @@ public class RevisionComparePage extends DepotPage {
protected void onInitialize() {
super.onInitialize();
- add(new Link<Void>("compareWithMergeBase") {
+ add(new Link<Void>("swap") {
@Override
public void onClick() {
- HistoryState state = new HistoryState(RevisionComparePage.this.state);
- state.compareWithMergeBase = true;
- PageParameters params = paramsOf(getDepot(), state);
+ HistoryState newState = new HistoryState(state);
+ newState.leftSide = state.rightSide;
+ newState.rightSide = state.leftSide;
+ PageParameters params = paramsOf(getDepot(), newState);
setResponsePage(RevisionComparePage.class, params);
}
@@ -340,8 +305,7 @@ public class RevisionComparePage extends DepotPage {
protected void onConfigure() {
super.onConfigure();
- setVisible(!state.compareWithMergeBase
- && !mergeBaseModel.getObject().equals(state.leftSide.getCommit().name()));
+ setVisible(!mergeBaseModel.getObject().equals(state.leftSide.getCommit().name()));
}
});
@@ -386,11 +350,7 @@ public class RevisionComparePage extends DepotPage {
}
private boolean hasChanges() {
- if (state.compareWithMergeBase) {
- return !mergeBaseModel.getObject().equals(state.rightSide.getCommit().name());
- } else {
- return !state.leftSide.getCommit().name().equals(state.rightSide.getCommit().name());
- }
+ return !mergeBaseModel.getObject().equals(state.rightSide.getCommit().name());
}
@Override
@@ -403,11 +363,20 @@ public class RevisionComparePage extends DepotPage {
private void newTabPanel(@Nullable AjaxRequestTarget target) {
WebMarkupContainer tabPanel;
if (state.pathFilter != null) {
+ IModel<Depot> depotModel = new LoadableDetachableModel<Depot>() {
+
+ @Override
+ protected Depot load() {
+ Depot depot = state.rightSide.getDepot();
+ depot.cacheObjectId(state.rightSide.getRevision(), resolvedRightSideRevision);
+ return depot;
+ }
+
+ };
tabPanel = new RevisionDiffPanel(TAB_PANEL_ID, depotModel,
- new Model<PullRequest>(null),
- state.compareWithMergeBase?mergeBaseModel.getObject():state.leftSide.getRevision(),
- state.rightSide.getRevision(), state.pathFilter,
- state.whitespaceOption, state.commentId) {
+ new Model<PullRequest>(null), mergeBaseModel.getObject(),
+ state.rightSide.getRevision(), state.pathFilter,
+ state.whitespaceOption, state.commentId) {
@Override
protected void onPathFilterChange(AjaxRequestTarget target, String pathFilter) {
@@ -497,7 +466,6 @@ public class RevisionComparePage extends DepotPage {
public HistoryState(HistoryState copy) {
leftSide = copy.leftSide;
rightSide = copy.rightSide;
- compareWithMergeBase = copy.compareWithMergeBase;
whitespaceOption = copy.whitespaceOption;
pathFilter = copy.pathFilter;
commentId = copy.commentId;
@@ -507,8 +475,6 @@ public class RevisionComparePage extends DepotPage {
public DepotAndRevision rightSide;
- public boolean compareWithMergeBase = true;
-
public WhitespaceOption whitespaceOption = WhitespaceOption.DEFAULT;
@Nullable
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java
index 680f5e1352..97e0062c33 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java
@@ -221,8 +221,7 @@ public class NewRequestPage extends PullRequestPage {
@Override
protected void onSelect(AjaxRequestTarget target, Depot depot, String branch) {
- PageParameters params = paramsOf(getDepot(),
- new DepotAndBranch(depot, branch), source);
+ PageParameters params = paramsOf(depot, new DepotAndBranch(depot, branch), source);
setResponsePage(NewRequestPage.class, params);
}
@@ -243,9 +242,9 @@ public class NewRequestPage extends PullRequestPage {
@Override
public void onClick() {
- setResponsePage(
- NewRequestPage.class,
- paramsOf(getDepot(), getPullRequest().getSource(), getPullRequest().getTarget()));
+ PageParameters params = paramsOf(getPullRequest().getSourceDepot(),
+ getPullRequest().getSource(), getPullRequest().getTarget());
+ setResponsePage(NewRequestPage.class, params);
}
});