# 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
* 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
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
} 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
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
* @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
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
* \r
* @return\r
*/\r
- @Override\r
public String getHtml() {\r
ByteArrayOutputStream bos = (ByteArrayOutputStream) os;\r
String html = RawParseUtils.decode(bos.toByteArray());\r
+++ /dev/null
-/*\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
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
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
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;
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) {
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;
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;
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,
@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