summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-09-18 11:20:28 -0400
committerJames Moger <james.moger@gitblit.com>2013-09-18 11:31:00 -0400
commit0250286553ca93406bfaa976d6aae61e76a9d55f (patch)
treea6edb6545a993c3e16709742d1bd177e33fcc9e7 /src
parentcd9461c0c05958444d1313b794be57df39d98956 (diff)
downloadgitblit-0250286553ca93406bfaa976d6aae61e76a9d55f.tar.gz
gitblit-0250286553ca93406bfaa976d6aae61e76a9d55f.zip
Removed GitWeb-style diff renderer
Diffstat (limited to 'src')
-rw-r--r--src/main/distrib/data/gitblit.properties5
-rw-r--r--src/main/java/com/gitblit/utils/DiffUtils.java11
-rw-r--r--src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java38
-rw-r--r--src/main/java/com/gitblit/utils/GitWebDiffFormatter.java155
-rw-r--r--src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java9
-rw-r--r--src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java6
-rw-r--r--src/main/java/com/gitblit/wicket/pages/ComparePage.java7
-rw-r--r--src/test/java/com/gitblit/tests/DiffUtilsTest.java3
8 files changed, 45 insertions, 189 deletions
diff --git a/src/main/distrib/data/gitblit.properties b/src/main/distrib/data/gitblit.properties
index 311152ad..b25e5aab 100644
--- a/src/main/distrib/data/gitblit.properties
+++ b/src/main/distrib/data/gitblit.properties
@@ -886,11 +886,6 @@ web.repositoryListSwatches = true
# SINCE 1.4.0
web.commitMessageRenderer = plain
-# Choose the diff presentation style: gitblt, gitweb, or plain
-#
-# SINCE 0.5.0
-web.diffStyle = gitblit
-
# Control if email addresses are shown in web ui
#
# SINCE 0.5.0
diff --git a/src/main/java/com/gitblit/utils/DiffUtils.java b/src/main/java/com/gitblit/utils/DiffUtils.java
index 67871d22..3844d103 100644
--- a/src/main/java/com/gitblit/utils/DiffUtils.java
+++ b/src/main/java/com/gitblit/utils/DiffUtils.java
@@ -53,7 +53,7 @@ public class DiffUtils {
* Enumeration for the diff output types.
*/
public static enum DiffOutputType {
- PLAIN, GITWEB, GITBLIT;
+ PLAIN, HTML;
public static DiffOutputType forName(String name) {
for (DiffOutputType type : values()) {
@@ -130,10 +130,7 @@ public class DiffUtils {
RawTextComparator cmp = RawTextComparator.DEFAULT;
DiffFormatter df;
switch (outputType) {
- case GITWEB:
- df = new GitWebDiffFormatter(os);
- break;
- case GITBLIT:
+ case HTML:
df = new GitBlitDiffFormatter(os);
break;
case PLAIN:
@@ -172,9 +169,9 @@ public class DiffUtils {
} else {
df.format(diffEntries);
}
- if (df instanceof GitWebDiffFormatter) {
+ if (df instanceof GitBlitDiffFormatter) {
// workaround for complex private methods in DiffFormatter
- diff = ((GitWebDiffFormatter) df).getHtml();
+ diff = ((GitBlitDiffFormatter) df).getHtml();
} else {
diff = os.toString();
}
diff --git a/src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java b/src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java
index 62966de0..a00e1076 100644
--- a/src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java
+++ b/src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java
@@ -16,12 +16,14 @@
package com.gitblit.utils;
import static org.eclipse.jgit.lib.Constants.encode;
+import static org.eclipse.jgit.lib.Constants.encodeASCII;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.MessageFormat;
+import org.eclipse.jgit.diff.DiffFormatter;
import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.util.RawParseUtils;
@@ -31,7 +33,7 @@ import org.eclipse.jgit.util.RawParseUtils;
* @author James Moger
*
*/
-public class GitBlitDiffFormatter extends GitWebDiffFormatter {
+public class GitBlitDiffFormatter extends DiffFormatter {
private final OutputStream os;
@@ -70,6 +72,39 @@ public class GitBlitDiffFormatter extends GitWebDiffFormatter {
left = aStartLine + 1;
right = bStartLine + 1;
}
+
+ protected void writeRange(final char prefix, final int begin, final int cnt) throws IOException {
+ os.write(' ');
+ os.write(prefix);
+ switch (cnt) {
+ case 0:
+ // If the range is empty, its beginning number must
+ // be the
+ // line just before the range, or 0 if the range is
+ // at the
+ // start of the file stream. Here, begin is always 1
+ // based,
+ // so an empty file would produce "0,0".
+ //
+ os.write(encodeASCII(begin - 1));
+ os.write(',');
+ os.write('0');
+ break;
+
+ case 1:
+ // If the range is exactly one line, produce only
+ // the number.
+ //
+ os.write(encodeASCII(begin));
+ break;
+
+ default:
+ os.write(encodeASCII(begin));
+ os.write(',');
+ os.write(encodeASCII(cnt));
+ break;
+ }
+ }
@Override
protected void writeLine(final char prefix, final RawText text, final int cur)
@@ -110,7 +145,6 @@ public class GitBlitDiffFormatter extends GitWebDiffFormatter {
*
* @return
*/
- @Override
public String getHtml() {
ByteArrayOutputStream bos = (ByteArrayOutputStream) os;
String html = RawParseUtils.decode(bos.toByteArray());
diff --git a/src/main/java/com/gitblit/utils/GitWebDiffFormatter.java b/src/main/java/com/gitblit/utils/GitWebDiffFormatter.java
deleted file mode 100644
index e657dc58..00000000
--- a/src/main/java/com/gitblit/utils/GitWebDiffFormatter.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright 2011 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.utils;
-
-import static org.eclipse.jgit.lib.Constants.encode;
-import static org.eclipse.jgit.lib.Constants.encodeASCII;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-import org.eclipse.jgit.diff.DiffFormatter;
-import org.eclipse.jgit.diff.RawText;
-import org.eclipse.jgit.util.RawParseUtils;
-
-/**
- * Returns an html snippet of the diff in the standard Gitweb style.
- *
- * @author James Moger
- *
- */
-public class GitWebDiffFormatter extends DiffFormatter {
-
- private final OutputStream os;
-
- public GitWebDiffFormatter(OutputStream os) {
- super(os);
- this.os = os;
- }
-
- /**
- * Output a hunk header
- *
- * @param aStartLine
- * within first source
- * @param aEndLine
- * within first source
- * @param bStartLine
- * within second source
- * @param bEndLine
- * within second source
- * @throws IOException
- */
- @Override
- protected void writeHunkHeader(int aStartLine, int aEndLine, int bStartLine, int bEndLine)
- throws IOException {
- os.write("<div class=\"diff hunk_header\"><span class=\"diff hunk_info\">".getBytes());
- os.write('@');
- os.write('@');
- writeRange('-', aStartLine + 1, aEndLine - aStartLine);
- writeRange('+', bStartLine + 1, bEndLine - bStartLine);
- os.write(' ');
- os.write('@');
- os.write('@');
- os.write("</span></div>".getBytes());
- }
-
- protected void writeRange(final char prefix, final int begin, final int cnt) throws IOException {
- os.write(' ');
- os.write(prefix);
- switch (cnt) {
- case 0:
- // If the range is empty, its beginning number must
- // be the
- // line just before the range, or 0 if the range is
- // at the
- // start of the file stream. Here, begin is always 1
- // based,
- // so an empty file would produce "0,0".
- //
- os.write(encodeASCII(begin - 1));
- os.write(',');
- os.write('0');
- break;
-
- case 1:
- // If the range is exactly one line, produce only
- // the number.
- //
- os.write(encodeASCII(begin));
- break;
-
- default:
- os.write(encodeASCII(begin));
- os.write(',');
- os.write(encodeASCII(cnt));
- break;
- }
- }
-
- @Override
- protected void writeLine(final char prefix, final RawText text, final int cur)
- throws IOException {
- switch (prefix) {
- case '+':
- os.write("<span style=\"color:#008000;\">".getBytes());
- break;
- case '-':
- os.write("<span style=\"color:#800000;\">".getBytes());
- break;
- }
- os.write(prefix);
- String line = text.getString(cur);
- line = StringUtils.escapeForHtml(line, false);
- os.write(encode(line));
- switch (prefix) {
- case '+':
- case '-':
- os.write("</span>\n".getBytes());
- break;
- default:
- os.write('\n');
- }
- }
-
- /**
- * Workaround function for complex private methods in DiffFormatter. This
- * sets the html for the diff headers.
- *
- * @return
- */
- public String getHtml() {
- ByteArrayOutputStream bos = (ByteArrayOutputStream) os;
- String html = RawParseUtils.decode(bos.toByteArray());
- String[] lines = html.split("\n");
- StringBuilder sb = new StringBuilder();
- sb.append("<div class=\"diff\">");
- for (String line : lines) {
- if (line.startsWith("diff")) {
- sb.append("<div class=\"diff header\">").append(StringUtils.convertOctal(line)).append("</div>");
- } else if (line.startsWith("---")) {
- sb.append("<span style=\"color:#800000;\">").append(StringUtils.convertOctal(line)).append("</span><br/>");
- } else if (line.startsWith("+++")) {
- sb.append("<span style=\"color:#008000;\">").append(StringUtils.convertOctal(line)).append("</span><br/>");
- } else {
- sb.append(line).append('\n');
- }
- }
- sb.append("</div>\n");
- return sb.toString();
- }
-}
diff --git a/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java b/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java
index c297bcaf..8dc9d840 100644
--- a/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java
@@ -21,8 +21,6 @@ import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
-import com.gitblit.GitBlit;
-import com.gitblit.Keys;
import com.gitblit.utils.DiffUtils;
import com.gitblit.utils.DiffUtils.DiffOutputType;
import com.gitblit.utils.JGitUtils;
@@ -45,19 +43,16 @@ public class BlobDiffPage extends RepositoryPage {
Repository r = getRepository();
RevCommit commit = getCommit();
- DiffOutputType diffType = DiffOutputType.forName(GitBlit.getString(Keys.web.diffStyle,
- DiffOutputType.GITBLIT.name()));
-
String diff;
if (StringUtils.isEmpty(baseObjectId)) {
// use first parent
- diff = DiffUtils.getDiff(r, commit, blobPath, diffType);
+ diff = DiffUtils.getDiff(r, commit, blobPath, DiffOutputType.HTML);
add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
} else {
// base commit specified
RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);
- diff = DiffUtils.getDiff(r, baseCommit, commit, blobPath, diffType);
+ diff = DiffUtils.getDiff(r, baseCommit, commit, blobPath, DiffOutputType.HTML);
add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
WicketUtils.newBlobDiffParameter(repositoryName, baseObjectId, objectId,
blobPath)));
diff --git a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
index 0a41b67b..4c802d74 100644
--- a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
@@ -30,7 +30,6 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import com.gitblit.GitBlit;
-import com.gitblit.Keys;
import com.gitblit.models.PathModel.PathChangeModel;
import com.gitblit.models.SubmoduleModel;
import com.gitblit.utils.DiffUtils;
@@ -51,12 +50,9 @@ public class CommitDiffPage extends RepositoryPage {
Repository r = getRepository();
- DiffOutputType diffType = DiffOutputType.forName(GitBlit.getString(Keys.web.diffStyle,
- DiffOutputType.GITBLIT.name()));
-
RevCommit commit = getCommit();
- String diff = DiffUtils.getCommitDiff(r, commit, diffType);
+ String diff = DiffUtils.getCommitDiff(r, commit, DiffOutputType.HTML);
List<String> parents = new ArrayList<String>();
if (commit.getParentCount() > 0) {
diff --git a/src/main/java/com/gitblit/wicket/pages/ComparePage.java b/src/main/java/com/gitblit/wicket/pages/ComparePage.java
index f5f35263..a513f00e 100644
--- a/src/main/java/com/gitblit/wicket/pages/ComparePage.java
+++ b/src/main/java/com/gitblit/wicket/pages/ComparePage.java
@@ -37,8 +37,6 @@ import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
-import com.gitblit.GitBlit;
-import com.gitblit.Keys;
import com.gitblit.models.PathModel.PathChangeModel;
import com.gitblit.models.RefModel;
import com.gitblit.models.RepositoryModel;
@@ -80,9 +78,6 @@ public class ComparePage extends RepositoryPage {
Fragment comparison = new Fragment("comparison", "comparisonFragment", this);
add(comparison);
- DiffOutputType diffType = DiffOutputType.forName(GitBlit.getString(Keys.web.diffStyle,
- DiffOutputType.GITBLIT.name()));
-
RevCommit fromCommit;
RevCommit toCommit;
@@ -113,7 +108,7 @@ public class ComparePage extends RepositoryPage {
fromCommitId.setObject(startId);
toCommitId.setObject(endId);
- String diff = DiffUtils.getDiff(r, fromCommit, toCommit, diffType);
+ String diff = DiffUtils.getDiff(r, fromCommit, toCommit, DiffOutputType.HTML);
// compare page links
// comparison.add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
diff --git a/src/test/java/com/gitblit/tests/DiffUtilsTest.java b/src/test/java/com/gitblit/tests/DiffUtilsTest.java
index 53eff313..b9700eb6 100644
--- a/src/test/java/com/gitblit/tests/DiffUtilsTest.java
+++ b/src/test/java/com/gitblit/tests/DiffUtilsTest.java
@@ -34,8 +34,7 @@ public class DiffUtilsTest {
@Test
public void testDiffOutputTypes() throws Exception {
assertEquals(DiffOutputType.PLAIN, DiffOutputType.forName("plain"));
- assertEquals(DiffOutputType.GITWEB, DiffOutputType.forName("gitweb"));
- assertEquals(DiffOutputType.GITBLIT, DiffOutputType.forName("gitblit"));
+ assertEquals(DiffOutputType.HTML, DiffOutputType.forName("html"));
assertEquals(null, DiffOutputType.forName(null));
}