]> source.dussan.org Git - gitblit.git/commitdiff
Removed GitWeb-style diff renderer
authorJames Moger <james.moger@gitblit.com>
Wed, 18 Sep 2013 15:20:28 +0000 (11:20 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 18 Sep 2013 15:31:00 +0000 (11:31 -0400)
src/main/distrib/data/gitblit.properties
src/main/java/com/gitblit/utils/DiffUtils.java
src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java
src/main/java/com/gitblit/utils/GitWebDiffFormatter.java [deleted file]
src/main/java/com/gitblit/wicket/pages/BlobDiffPage.java
src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
src/main/java/com/gitblit/wicket/pages/ComparePage.java
src/test/java/com/gitblit/tests/DiffUtilsTest.java

index 311152ad18a80c55e66c5443bb0c8e78bc20c468..b25e5aab2f86c1ec7419274fdc3069543e8812e1 100644 (file)
@@ -886,11 +886,6 @@ web.repositoryListSwatches = true
 # SINCE 1.4.0\r
 web.commitMessageRenderer = plain\r
 \r
-# Choose the diff presentation style: gitblt, gitweb, or plain\r
-#\r
-# SINCE 0.5.0\r
-web.diffStyle = gitblit\r
-\r
 # Control if email addresses are shown in web ui\r
 #\r
 # SINCE 0.5.0\r
index 67871d2234829ebdcc62a04f2f519b70a52c7d1a..3844d10358e3fedcff9f138b599d6a716a5261a6 100644 (file)
@@ -53,7 +53,7 @@ public class DiffUtils {
         * Enumeration for the diff output types.\r
         */\r
        public static enum DiffOutputType {\r
-               PLAIN, GITWEB, GITBLIT;\r
+               PLAIN, HTML;\r
 \r
                public static DiffOutputType forName(String name) {\r
                        for (DiffOutputType type : values()) {\r
@@ -130,10 +130,7 @@ public class DiffUtils {
                        RawTextComparator cmp = RawTextComparator.DEFAULT;\r
                        DiffFormatter df;\r
                        switch (outputType) {\r
-                       case GITWEB:\r
-                               df = new GitWebDiffFormatter(os);\r
-                               break;\r
-                       case GITBLIT:\r
+                       case HTML:\r
                                df = new GitBlitDiffFormatter(os);\r
                                break;\r
                        case PLAIN:\r
@@ -172,9 +169,9 @@ public class DiffUtils {
                        } else {\r
                                df.format(diffEntries);\r
                        }\r
-                       if (df instanceof GitWebDiffFormatter) {\r
+                       if (df instanceof GitBlitDiffFormatter) {\r
                                // workaround for complex private methods in DiffFormatter\r
-                               diff = ((GitWebDiffFormatter) df).getHtml();\r
+                               diff = ((GitBlitDiffFormatter) df).getHtml();\r
                        } else {\r
                                diff = os.toString();\r
                        }\r
index 62966de096be297fa29c8568648b0b64e511df78..a00e1076b59c5c68a8ba74e3a41101325174f2d5 100644 (file)
 package com.gitblit.utils;\r
 \r
 import static org.eclipse.jgit.lib.Constants.encode;\r
+import static org.eclipse.jgit.lib.Constants.encodeASCII;\r
 \r
 import java.io.ByteArrayOutputStream;\r
 import java.io.IOException;\r
 import java.io.OutputStream;\r
 import java.text.MessageFormat;\r
 \r
+import org.eclipse.jgit.diff.DiffFormatter;\r
 import org.eclipse.jgit.diff.RawText;\r
 import org.eclipse.jgit.util.RawParseUtils;\r
 \r
@@ -31,7 +33,7 @@ import org.eclipse.jgit.util.RawParseUtils;
  * @author James Moger\r
  * \r
  */\r
-public class GitBlitDiffFormatter extends GitWebDiffFormatter {\r
+public class GitBlitDiffFormatter extends DiffFormatter {\r
 \r
        private final OutputStream os;\r
 \r
@@ -70,6 +72,39 @@ public class GitBlitDiffFormatter extends GitWebDiffFormatter {
                left = aStartLine + 1;\r
                right = bStartLine + 1;\r
        }\r
+       \r
+       protected void writeRange(final char prefix, final int begin, final int cnt) throws IOException {\r
+               os.write(' ');\r
+               os.write(prefix);\r
+               switch (cnt) {\r
+               case 0:\r
+                       // If the range is empty, its beginning number must\r
+                       // be the\r
+                       // line just before the range, or 0 if the range is\r
+                       // at the\r
+                       // start of the file stream. Here, begin is always 1\r
+                       // based,\r
+                       // so an empty file would produce "0,0".\r
+                       //\r
+                       os.write(encodeASCII(begin - 1));\r
+                       os.write(',');\r
+                       os.write('0');\r
+                       break;\r
+\r
+               case 1:\r
+                       // If the range is exactly one line, produce only\r
+                       // the number.\r
+                       //\r
+                       os.write(encodeASCII(begin));\r
+                       break;\r
+\r
+               default:\r
+                       os.write(encodeASCII(begin));\r
+                       os.write(',');\r
+                       os.write(encodeASCII(cnt));\r
+                       break;\r
+               }\r
+       }\r
 \r
        @Override\r
        protected void writeLine(final char prefix, final RawText text, final int cur)\r
@@ -110,7 +145,6 @@ public class GitBlitDiffFormatter extends GitWebDiffFormatter {
         * \r
         * @return\r
         */\r
-       @Override\r
        public String getHtml() {\r
                ByteArrayOutputStream bos = (ByteArrayOutputStream) os;\r
                String html = RawParseUtils.decode(bos.toByteArray());\r
diff --git a/src/main/java/com/gitblit/utils/GitWebDiffFormatter.java b/src/main/java/com/gitblit/utils/GitWebDiffFormatter.java
deleted file mode 100644 (file)
index e657dc5..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-/*\r
- * Copyright 2011 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit.utils;\r
-\r
-import static org.eclipse.jgit.lib.Constants.encode;\r
-import static org.eclipse.jgit.lib.Constants.encodeASCII;\r
-\r
-import java.io.ByteArrayOutputStream;\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-\r
-import org.eclipse.jgit.diff.DiffFormatter;\r
-import org.eclipse.jgit.diff.RawText;\r
-import org.eclipse.jgit.util.RawParseUtils;\r
-\r
-/**\r
- * Returns an html snippet of the diff in the standard Gitweb style.\r
- * \r
- * @author James Moger\r
- * \r
- */\r
-public class GitWebDiffFormatter extends DiffFormatter {\r
-\r
-       private final OutputStream os;\r
-\r
-       public GitWebDiffFormatter(OutputStream os) {\r
-               super(os);\r
-               this.os = os;\r
-       }\r
-\r
-       /**\r
-        * Output a hunk header\r
-        * \r
-        * @param aStartLine\r
-        *            within first source\r
-        * @param aEndLine\r
-        *            within first source\r
-        * @param bStartLine\r
-        *            within second source\r
-        * @param bEndLine\r
-        *            within second source\r
-        * @throws IOException\r
-        */\r
-       @Override\r
-       protected void writeHunkHeader(int aStartLine, int aEndLine, int bStartLine, int bEndLine)\r
-                       throws IOException {\r
-               os.write("<div class=\"diff hunk_header\"><span class=\"diff hunk_info\">".getBytes());\r
-               os.write('@');\r
-               os.write('@');\r
-               writeRange('-', aStartLine + 1, aEndLine - aStartLine);\r
-               writeRange('+', bStartLine + 1, bEndLine - bStartLine);\r
-               os.write(' ');\r
-               os.write('@');\r
-               os.write('@');\r
-               os.write("</span></div>".getBytes());\r
-       }\r
-\r
-       protected void writeRange(final char prefix, final int begin, final int cnt) throws IOException {\r
-               os.write(' ');\r
-               os.write(prefix);\r
-               switch (cnt) {\r
-               case 0:\r
-                       // If the range is empty, its beginning number must\r
-                       // be the\r
-                       // line just before the range, or 0 if the range is\r
-                       // at the\r
-                       // start of the file stream. Here, begin is always 1\r
-                       // based,\r
-                       // so an empty file would produce "0,0".\r
-                       //\r
-                       os.write(encodeASCII(begin - 1));\r
-                       os.write(',');\r
-                       os.write('0');\r
-                       break;\r
-\r
-               case 1:\r
-                       // If the range is exactly one line, produce only\r
-                       // the number.\r
-                       //\r
-                       os.write(encodeASCII(begin));\r
-                       break;\r
-\r
-               default:\r
-                       os.write(encodeASCII(begin));\r
-                       os.write(',');\r
-                       os.write(encodeASCII(cnt));\r
-                       break;\r
-               }\r
-       }\r
-\r
-       @Override\r
-       protected void writeLine(final char prefix, final RawText text, final int cur)\r
-                       throws IOException {\r
-               switch (prefix) {\r
-               case '+':\r
-                       os.write("<span style=\"color:#008000;\">".getBytes());\r
-                       break;\r
-               case '-':\r
-                       os.write("<span style=\"color:#800000;\">".getBytes());\r
-                       break;\r
-               }\r
-               os.write(prefix);\r
-               String line = text.getString(cur);\r
-               line = StringUtils.escapeForHtml(line, false);\r
-               os.write(encode(line));\r
-               switch (prefix) {\r
-               case '+':\r
-               case '-':\r
-                       os.write("</span>\n".getBytes());\r
-                       break;\r
-               default:\r
-                       os.write('\n');\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Workaround function for complex private methods in DiffFormatter. This\r
-        * sets the html for the diff headers.\r
-        * \r
-        * @return\r
-        */\r
-       public String getHtml() {\r
-               ByteArrayOutputStream bos = (ByteArrayOutputStream) os;\r
-               String html = RawParseUtils.decode(bos.toByteArray());\r
-               String[] lines = html.split("\n");\r
-               StringBuilder sb = new StringBuilder();\r
-               sb.append("<div class=\"diff\">");\r
-               for (String line : lines) {\r
-                       if (line.startsWith("diff")) {\r
-                               sb.append("<div class=\"diff header\">").append(StringUtils.convertOctal(line)).append("</div>");\r
-                       } else if (line.startsWith("---")) {\r
-                               sb.append("<span style=\"color:#800000;\">").append(StringUtils.convertOctal(line)).append("</span><br/>");\r
-                       } else if (line.startsWith("+++")) {\r
-                               sb.append("<span style=\"color:#008000;\">").append(StringUtils.convertOctal(line)).append("</span><br/>");\r
-                       } else {\r
-                               sb.append(line).append('\n');\r
-                       }\r
-               }\r
-               sb.append("</div>\n");\r
-               return sb.toString();\r
-       }\r
-}\r
index c297bcaf2721744a95732aa8af00de5b1ea142c9..8dc9d8405f6405305a5ad202fe577b4ad8fa53c7 100644 (file)
@@ -21,8 +21,6 @@ import org.apache.wicket.markup.html.link.BookmarkablePageLink;
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
-import com.gitblit.GitBlit;\r
-import com.gitblit.Keys;\r
 import com.gitblit.utils.DiffUtils;\r
 import com.gitblit.utils.DiffUtils.DiffOutputType;\r
 import com.gitblit.utils.JGitUtils;\r
@@ -45,19 +43,16 @@ public class BlobDiffPage extends RepositoryPage {
                Repository r = getRepository();\r
                RevCommit commit = getCommit();\r
 \r
-               DiffOutputType diffType = DiffOutputType.forName(GitBlit.getString(Keys.web.diffStyle,\r
-                               DiffOutputType.GITBLIT.name()));\r
-\r
                String diff;\r
                if (StringUtils.isEmpty(baseObjectId)) {\r
                        // use first parent\r
-                       diff = DiffUtils.getDiff(r, commit, blobPath, diffType);\r
+                       diff = DiffUtils.getDiff(r, commit, blobPath, DiffOutputType.HTML);\r
                        add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,\r
                                        WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));\r
                } else {\r
                        // base commit specified\r
                        RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);\r
-                       diff = DiffUtils.getDiff(r, baseCommit, commit, blobPath, diffType);\r
+                       diff = DiffUtils.getDiff(r, baseCommit, commit, blobPath, DiffOutputType.HTML);\r
                        add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,\r
                                        WicketUtils.newBlobDiffParameter(repositoryName, baseObjectId, objectId,\r
                                                        blobPath)));\r
index 0a41b67b9b4b5766f2ffb79275bfc256d86d2a40..4c802d747b8519b70cf53e33074c9d5e650e0710 100644 (file)
@@ -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) {
index f5f3526358ee7c159bc80e068a1664b5a13ba655..a513f00ec79208a84c537da475751b74c09033b3 100644 (file)
@@ -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,
index 53eff3132f4f32d547a3d4aee6825c8ca9908719..b9700eb62ea46c4731bf8f02938543825712f815 100644 (file)
@@ -34,8 +34,7 @@ public class DiffUtilsTest {
        @Test\r
        public void testDiffOutputTypes() throws Exception {\r
                assertEquals(DiffOutputType.PLAIN, DiffOutputType.forName("plain"));\r
-               assertEquals(DiffOutputType.GITWEB, DiffOutputType.forName("gitweb"));\r
-               assertEquals(DiffOutputType.GITBLIT, DiffOutputType.forName("gitblit"));\r
+               assertEquals(DiffOutputType.HTML, DiffOutputType.forName("html"));\r
                assertEquals(null, DiffOutputType.forName(null));\r
        }\r
 \r