From 2e141ff31dedaa6dfefc4af47eda803d8dbb3eff Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Tue, 01 Sep 2015 08:49:02 -0400
Subject: [PATCH] Fix #909: Add missing SLFJ dependencies in Manager build
---
src/main/java/com/gitblit/wicket/pages/ComparePage.java | 72 +++++++++++++++++++++++++++---------
1 files changed, 54 insertions(+), 18 deletions(-)
diff --git a/src/main/java/com/gitblit/wicket/pages/ComparePage.java b/src/main/java/com/gitblit/wicket/pages/ComparePage.java
index 1efb9b6..7e7ac2f 100644
--- a/src/main/java/com/gitblit/wicket/pages/ComparePage.java
+++ b/src/main/java/com/gitblit/wicket/pages/ComparePage.java
@@ -21,6 +21,7 @@
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
@@ -37,11 +38,14 @@
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
+import com.gitblit.Keys;
import com.gitblit.models.PathModel.PathChangeModel;
import com.gitblit.models.RefModel;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.SubmoduleModel;
+import com.gitblit.servlet.RawServlet;
import com.gitblit.utils.DiffUtils;
+import com.gitblit.utils.DiffUtils.DiffComparator;
import com.gitblit.utils.DiffUtils.DiffOutput;
import com.gitblit.utils.DiffUtils.DiffOutputType;
import com.gitblit.utils.JGitUtils;
@@ -55,7 +59,7 @@
/**
* The compare page allows you to compare two branches, tags, or hash ids.
- *
+ *
* @author James Moger
*
*/
@@ -67,11 +71,13 @@
IModel<String> fromRefId = new Model<String>("");
IModel<String> toRefId = new Model<String>("");
+ IModel<Boolean> ignoreWhitespace = Model.of(true);
+
public ComparePage(PageParameters params) {
super(params);
Repository r = getRepository();
RepositoryModel repository = getRepositoryModel();
-
+
if (StringUtils.isEmpty(objectId)) {
// seleciton form
add(new Label("comparison").setVisible(false));
@@ -79,30 +85,30 @@
// active comparison
Fragment comparison = new Fragment("comparison", "comparisonFragment", this);
add(comparison);
-
+
RevCommit fromCommit;
RevCommit toCommit;
-
+
String[] parts = objectId.split("\\.\\.");
if (parts[0].startsWith("refs/") && parts[1].startsWith("refs/")) {
// set the ref models
fromRefId.setObject(parts[0]);
toRefId.setObject(parts[1]);
-
+
fromCommit = getCommit(r, fromRefId.getObject());
toCommit = getCommit(r, toRefId.getObject());
} else {
// set the id models
fromCommitId.setObject(parts[0]);
toCommitId.setObject(parts[1]);
-
+
fromCommit = getCommit(r, fromCommitId.getObject());
toCommit = getCommit(r, toCommitId.getObject());
}
// prepare submodules
getSubmodules(toCommit);
-
+
final String startId = fromCommit.getId().getName();
final String endId = toCommit.getId().getName();
@@ -110,7 +116,15 @@
fromCommitId.setObject(startId);
toCommitId.setObject(endId);
- final DiffOutput diff = DiffUtils.getDiff(r, fromCommit, toCommit, DiffOutputType.HTML);
+ final List<String> imageExtensions = app().settings().getStrings(Keys.web.imageExtensions);
+ final ImageDiffHandler handler = new ImageDiffHandler(this, repositoryName,
+ fromCommit.getName(), toCommit.getName(), imageExtensions);
+ final DiffComparator diffComparator = WicketUtils.getDiffComparator(params);
+ final int tabLength = app().settings().getInteger(Keys.web.tabLength, 4);
+ final DiffOutput diff = DiffUtils.getDiff(r, fromCommit, toCommit, diffComparator, DiffOutputType.HTML, handler, tabLength);
+ if (handler.getImgDiffCount() > 0) {
+ addBottomScript("scripts/imgdiff.js"); // Tiny support script for image diffs
+ }
// add compare diffstat
int insertions = 0;
@@ -135,6 +149,7 @@
private static final long serialVersionUID = 1L;
int counter;
+ @Override
public void populateItem(final Item<PathChangeModel> item) {
final PathChangeModel entry = item.getModelObject();
Label changeType = new Label("changeType", "");
@@ -158,10 +173,10 @@
hasSubmodule = submodule.hasSubmodule;
// add relative link
- item.add(new LinkPanel("pathName", "list", entry.path + " @ " + getShortObjectId(submoduleId), "#" + entry.path));
+ item.add(new LinkPanel("pathName", "list", entry.path + " @ " + getShortObjectId(submoduleId), "#n" + entry.objectId));
} else {
// add relative link
- item.add(new LinkPanel("pathName", "list", entry.path, "#" + entry.path));
+ item.add(new LinkPanel("pathName", "list", entry.path, "#n" + entry.objectId));
}
// quick links
@@ -170,6 +185,7 @@
item.add(new ExternalLink("patch", "").setEnabled(false));
item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils
.newObjectParameter(submodulePath, entry.objectId)).setEnabled(hasSubmodule));
+ item.add(new ExternalLink("raw", "").setEnabled(false));
item.add(new ExternalLink("blame", "").setEnabled(false));
item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils
.newPathParameter(repositoryName, endId, entry.path))
@@ -181,6 +197,9 @@
.setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils
.newPathParameter(repositoryName, endId, entry.path))
+ .setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
+ String rawUrl = RawServlet.asLink(getContextUrl(), repositoryName, endId, entry.path);
+ item.add(new ExternalLink("raw", rawUrl)
.setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class, WicketUtils
.newPathParameter(repositoryName, endId, entry.path))
@@ -198,6 +217,10 @@
comparison.add(new Label("diffText", diff.content).setEscapeModelStrings(false));
}
+ // set the default DiffComparator
+ DiffComparator diffComparator = WicketUtils.getDiffComparator(params);
+ ignoreWhitespace.setObject(DiffComparator.IGNORE_WHITESPACE == diffComparator);
+
//
// ref selection form
//
@@ -209,14 +232,19 @@
public void onSubmit() {
String from = ComparePage.this.fromRefId.getObject();
String to = ComparePage.this.toRefId.getObject();
-
+ boolean ignoreWS = ignoreWhitespace.getObject();
+
PageParameters params = WicketUtils.newRangeParameter(repositoryName, from, to);
+ if (ignoreWS) {
+ params.put("w", 1);
+ }
+
String relativeUrl = urlFor(ComparePage.class, params).toString();
String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
}
};
-
+
List<String> refs = new ArrayList<String>();
for (RefModel ref : JGitUtils.getLocalBranches(r, true, -1)) {
refs.add(ref.getName());
@@ -231,8 +259,10 @@
}
refsForm.add(new DropDownChoice<String>("fromRef", fromRefId, refs).setEnabled(refs.size() > 0));
refsForm.add(new DropDownChoice<String>("toRef", toRefId, refs).setEnabled(refs.size() > 0));
+ refsForm.add(new Label("ignoreWhitespaceLabel", getString(DiffComparator.IGNORE_WHITESPACE.getTranslationKey())));
+ refsForm.add(new CheckBox("ignoreWhitespaceCheckbox", ignoreWhitespace));
add(refsForm);
-
+
//
// manual ids form
//
@@ -244,23 +274,29 @@
public void onSubmit() {
String from = ComparePage.this.fromCommitId.getObject();
String to = ComparePage.this.toCommitId.getObject();
-
+ boolean ignoreWS = ignoreWhitespace.getObject();
+
PageParameters params = WicketUtils.newRangeParameter(repositoryName, from, to);
+ if (ignoreWS) {
+ params.put("w", 1);
+ }
String relativeUrl = urlFor(ComparePage.class, params).toString();
String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
}
};
-
+
TextField<String> fromIdField = new TextField<String>("fromId", fromCommitId);
WicketUtils.setInputPlaceholder(fromIdField, getString("gb.from") + "...");
idsForm.add(fromIdField);
-
+
TextField<String> toIdField = new TextField<String>("toId", toCommitId);
WicketUtils.setInputPlaceholder(toIdField, getString("gb.to") + "...");
idsForm.add(toIdField);
+ idsForm.add(new Label("ignoreWhitespaceLabel", getString(DiffComparator.IGNORE_WHITESPACE.getTranslationKey())));
+ idsForm.add(new CheckBox("ignoreWhitespaceCheckbox", ignoreWhitespace));
add(idsForm);
-
+
r.close();
}
@@ -268,7 +304,7 @@
protected String getPageName() {
return getString("gb.compare");
}
-
+
@Override
protected Class<? extends BasePage> getRepoNavPageClass() {
return ComparePage.class;
--
Gitblit v1.9.1