# BASEFOLDER
web.projectsFile = ${baseFolder}/projects.conf
+# Defines the tab length for all blob views
+#
+# SINCE 1.7.0
+web.tabLength = 4
+
# Either the full path to a user config file (users.conf)
# OR a fully qualified class name that implements the IUserService interface.
#
content = "";\r
}\r
\r
+ int tabLength = storedSettings.getInteger(Keys.web.tabLength, 4);\r
int fragmentLength = SearchObjectType.commit == result.type ? 512 : 150;\r
\r
QueryScorer scorer = new QueryScorer(query, "content");\r
if (fragment.length() > fragmentLength) {\r
fragment = fragment.substring(0, fragmentLength) + "...";\r
}\r
- return "<pre class=\"text\">" + StringUtils.escapeForHtml(fragment, true) + "</pre>";\r
+ return "<pre class=\"text\">" + StringUtils.escapeForHtml(fragment, true, tabLength) + "</pre>";\r
}\r
\r
// make sure we have unique fragments\r
* @param commit\r
* @param comparator\r
* @param outputType\r
+ * @param tabLength\r
* @return the diff\r
*/\r
public static DiffOutput getCommitDiff(Repository repository, RevCommit commit,\r
- DiffComparator comparator, DiffOutputType outputType) {\r
- return getDiff(repository, null, commit, null, comparator, outputType);\r
+ DiffComparator comparator, DiffOutputType outputType, int tabLength) {\r
+ return getDiff(repository, null, commit, null, comparator, outputType, tabLength);\r
}\r
\r
/**\r
* @param handler\r
* to use for rendering binary diffs if {@code outputType} is {@link DiffOutputType#HTML HTML}.\r
* May be {@code null}, resulting in the default behavior.\r
+ * @param tabLength\r
* @return the diff\r
*/\r
public static DiffOutput getCommitDiff(Repository repository, RevCommit commit,\r
- DiffComparator comparator, DiffOutputType outputType, BinaryDiffHandler handler) {\r
- return getDiff(repository, null, commit, null, comparator, outputType, handler);\r
+ DiffComparator comparator, DiffOutputType outputType, BinaryDiffHandler handler, int tabLength) {\r
+ return getDiff(repository, null, commit, null, comparator, outputType, handler, tabLength);\r
}\r
\r
\r
* @param path\r
* @param comparator\r
* @param outputType\r
+ * @param tabLength\r
* @return the diff\r
*/\r
public static DiffOutput getDiff(Repository repository, RevCommit commit, String path,\r
- DiffComparator comparator, DiffOutputType outputType) {\r
- return getDiff(repository, null, commit, path, comparator, outputType);\r
+ DiffComparator comparator, DiffOutputType outputType, int tabLength) {\r
+ return getDiff(repository, null, commit, path, comparator, outputType, tabLength);\r
}\r
\r
/**\r
* @param handler\r
* to use for rendering binary diffs if {@code outputType} is {@link DiffOutputType#HTML HTML}.\r
* May be {@code null}, resulting in the default behavior.\r
+ * @param tabLength\r
* @return the diff\r
*/\r
public static DiffOutput getDiff(Repository repository, RevCommit commit, String path,\r
- DiffComparator comparator, DiffOutputType outputType, BinaryDiffHandler handler) {\r
- return getDiff(repository, null, commit, path, comparator, outputType, handler);\r
+ DiffComparator comparator, DiffOutputType outputType, BinaryDiffHandler handler, int tabLength) {\r
+ return getDiff(repository, null, commit, path, comparator, outputType, handler, tabLength);\r
}\r
\r
/**\r
* @param commit\r
* @param comparator\r
* @param outputType\r
+ * @param tabLength\r
+ *\r
* @return the diff\r
*/\r
public static DiffOutput getDiff(Repository repository, RevCommit baseCommit, RevCommit commit,\r
- DiffComparator comparator, DiffOutputType outputType) {\r
- return getDiff(repository, baseCommit, commit, null, comparator, outputType);\r
+ DiffComparator comparator, DiffOutputType outputType, int tabLength) {\r
+ return getDiff(repository, baseCommit, commit, null, comparator, outputType, tabLength);\r
}\r
\r
/**\r
* @param handler\r
* to use for rendering binary diffs if {@code outputType} is {@link DiffOutputType#HTML HTML}.\r
* May be {@code null}, resulting in the default behavior.\r
+ * @param tabLength\r
* @return the diff\r
*/\r
public static DiffOutput getDiff(Repository repository, RevCommit baseCommit, RevCommit commit,\r
- DiffComparator comparator, DiffOutputType outputType, BinaryDiffHandler handler) {\r
- return getDiff(repository, baseCommit, commit, null, comparator, outputType, handler);\r
+ DiffComparator comparator, DiffOutputType outputType, BinaryDiffHandler handler, int tabLength) {\r
+ return getDiff(repository, baseCommit, commit, null, comparator, outputType, handler, tabLength);\r
}\r
\r
/**\r
* or folder. if unspecified, the diff is for the entire commit.\r
* @param outputType\r
* @param diffComparator\r
+ * @param tabLength\r
* @return the diff\r
*/\r
public static DiffOutput getDiff(Repository repository, RevCommit baseCommit, RevCommit commit,\r
- String path, DiffComparator diffComparator, DiffOutputType outputType) {\r
- return getDiff(repository, baseCommit, commit, path, diffComparator, outputType, null);\r
+ String path, DiffComparator diffComparator, DiffOutputType outputType, int tabLength) {\r
+ return getDiff(repository, baseCommit, commit, path, diffComparator, outputType, null, tabLength);\r
}\r
\r
/**\r
* @param handler\r
* to use for rendering binary diffs if {@code outputType} is {@link DiffOutputType#HTML HTML}.\r
* May be {@code null}, resulting in the default behavior.\r
+ * @param tabLength\r
* @return the diff\r
*/\r
public static DiffOutput getDiff(Repository repository, RevCommit baseCommit, RevCommit commit, String path,\r
- DiffComparator comparator, DiffOutputType outputType, final BinaryDiffHandler handler) {\r
+ DiffComparator comparator, DiffOutputType outputType, final BinaryDiffHandler handler, int tabLength) {\r
DiffStat stat = null;\r
String diff = null;\r
try {\r
DiffFormatter df;\r
switch (outputType) {\r
case HTML:\r
- df = new GitBlitDiffFormatter(commit.getName(), path, handler);\r
+ df = new GitBlitDiffFormatter(commit.getName(), path, handler, tabLength);\r
break;\r
case PLAIN:\r
default:\r
/** If {@link #truncated}, contains all entries skipped. */
private final List<DiffEntry> skipped = new ArrayList<DiffEntry>();
+ private int tabLength;
+
/**
* A {@link ResettableByteArrayOutputStream} that intercept the "Binary files differ" message produced
* by the super implementation. Unfortunately the super implementation has far too many things private;
}
- public GitBlitDiffFormatter(String commitId, String path, BinaryDiffHandler handler) {
+ public GitBlitDiffFormatter(String commitId, String path, BinaryDiffHandler handler, int tabLength) {
super(new DiffOutputStream());
this.os = (DiffOutputStream) getOutputStream();
this.os.setFormatter(this, handler);
this.diffStat = new DiffStat(commitId);
+ this.tabLength = tabLength;
// If we have a full commitdiff, install maxima to avoid generating a super-long diff listing that
// will only tax the browser too much.
maxDiffLinesPerFile = path != null ? -1 : getLimit(DIFF_LIMIT_PER_FILE_KEY, 500, DIFF_LIMIT_PER_FILE);
// Highlight trailing whitespace on deleted/added lines.
Matcher matcher = trailingWhitespace.matcher(line);
if (matcher.find()) {
- StringBuilder result = new StringBuilder(StringUtils.escapeForHtml(line.substring(0, matcher.start()), CONVERT_TABS));
+ StringBuilder result = new StringBuilder(StringUtils.escapeForHtml(line.substring(0, matcher.start()), CONVERT_TABS, tabLength));
result.append("<span class='trailingws-").append(prefix == '+' ? "add" : "sub").append("'>");
result.append(StringUtils.escapeForHtml(matcher.group(1), false));
result.append("</span>");
return result.toString();
}
}
- return StringUtils.escapeForHtml(line, CONVERT_TABS);
+ return StringUtils.escapeForHtml(line, CONVERT_TABS, tabLength);
}
/**
} else {
sb.append("<th class='diff-state diff-state-sub'></th><td class=\"diff-cell remove2\">");
}
- line = StringUtils.escapeForHtml(line.substring(1), CONVERT_TABS);
+ line = StringUtils.escapeForHtml(line.substring(1), CONVERT_TABS, tabLength);
}
sb.append(line);
if (gitLinkDiff) {
* @return plain text escaped for html\r
*/\r
public static String escapeForHtml(String inStr, boolean changeSpace) {\r
+ return escapeForHtml(inStr, changeSpace, 4);\r
+ }\r
+\r
+ /**\r
+ * Prepare text for html presentation. Replace sensitive characters with\r
+ * html entities.\r
+ *\r
+ * @param inStr\r
+ * @param changeSpace\r
+ * @param tabLength\r
+ * @return plain text escaped for html\r
+ */\r
+ public static String escapeForHtml(String inStr, boolean changeSpace, int tabLength) {\r
StringBuilder retStr = new StringBuilder();\r
int i = 0;\r
while (i < inStr.length()) {\r
} else if (changeSpace && inStr.charAt(i) == ' ') {\r
retStr.append(" ");\r
} else if (changeSpace && inStr.charAt(i) == '\t') {\r
- retStr.append(" ");\r
+ for (int j = 0; j < tabLength; j++) {\r
+ retStr.append(" ");\r
+ }\r
} else {\r
retStr.append(inStr.charAt(i));\r
}\r
\r
add(new Label("missingBlob").setVisible(false));\r
\r
+ final int tabLength = app().settings().getInteger(Keys.web.tabLength, 4);\r
List<AnnotatedLine> lines = DiffUtils.blame(getRepository(), blobPath, objectId);\r
final Map<?, String> colorMap = initializeColors(activeBlameType, lines);\r
ListDataProvider<AnnotatedLine> blameDp = new ListDataProvider<AnnotatedLine>(lines);\r
color = colorMap.get(entry.commitId);\r
break;\r
}\r
- Component data = new Label("data", StringUtils.escapeForHtml(entry.data, true)).setEscapeModelStrings(false);\r
+ Component data = new Label("data", StringUtils.escapeForHtml(entry.data, true, tabLength)).setEscapeModelStrings(false);\r
data.add(new SimpleAttributeModifier("style", "background-color: " + color + ";"));\r
item.add(data);\r
}\r
RevCommit parent = commit.getParentCount() == 0 ? null : commit.getParent(0);\r
ImageDiffHandler handler = new ImageDiffHandler(this, repositoryName,\r
parent.getName(), commit.getName(), imageExtensions);\r
- diff = DiffUtils.getDiff(r, commit, blobPath, diffComparator, DiffOutputType.HTML, handler).content;\r
+ diff = DiffUtils.getDiff(r, commit, blobPath, diffComparator, DiffOutputType.HTML, handler, 3).content;\r
if (handler.getImgDiffCount() > 0) {\r
addBottomScript("scripts/imgdiff.js"); // Tiny support script for image diffs\r
}\r
RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);\r
ImageDiffHandler handler = new ImageDiffHandler(this, repositoryName,\r
baseCommit.getName(), commit.getName(), imageExtensions);\r
- diff = DiffUtils.getDiff(r, baseCommit, commit, blobPath, diffComparator, DiffOutputType.HTML, handler).content;\r
+ diff = DiffUtils.getDiff(r, baseCommit, commit, blobPath, diffComparator, DiffOutputType.HTML, handler, 3).content;\r
if (handler.getImgDiffCount() > 0) {\r
addBottomScript("scripts/imgdiff.js"); // Tiny support script for image diffs\r
}\r
} else {\r
sb.append("<pre class=\"plainprint\">");\r
}\r
- lines = StringUtils.escapeForHtml(source, true).split("\n");\r
+ final int tabLength = app().settings().getInteger(Keys.web.tabLength, 4);\r
+ lines = StringUtils.escapeForHtml(source, true, tabLength).split("\n");\r
\r
sb.append("<table width=\"100%\"><tbody>");\r
\r
final List<String> imageExtensions = app().settings().getStrings(Keys.web.imageExtensions);
final ImageDiffHandler handler = new ImageDiffHandler(this, repositoryName,
parents.isEmpty() ? null : parents.get(0), commit.getName(), imageExtensions);
-
- final DiffOutput diff = DiffUtils.getCommitDiff(r, commit, diffComparator, DiffOutputType.HTML, handler);
+ final int tabLength = app().settings().getInteger(Keys.web.tabLength, 4);
+ final DiffOutput diff = DiffUtils.getCommitDiff(r, commit, diffComparator, DiffOutputType.HTML, handler, tabLength);
if (handler.getImgDiffCount() > 0) {
addBottomScript("scripts/imgdiff.js"); // Tiny support script for image diffs
}
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 DiffOutput diff = DiffUtils.getDiff(r, fromCommit, toCommit, diffComparator, DiffOutputType.HTML, handler);
+ 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
}
sb.append(asParam(p, proposal.name, "exclude", ""));\r
sb.append(asParam(p, proposal.name, "include", ""));\r
\r
+ final int tabLength = app().settings().getInteger(Keys.web.tabLength, 4);\r
add(new Label("definition", StringUtils.breakLinesForHtml(StringUtils.escapeForHtml(sb\r
- .toString().trim(), true))).setEscapeModelStrings(false));\r
+ .toString().trim(), true, tabLength))).setEscapeModelStrings(false));\r
\r
List<RepositoryModel> repositories = new ArrayList<RepositoryModel>(\r
proposal.repositories.values());\r
Repository repository = GitBlitSuite.getHelloworldRepository();\r
RevCommit commit = JGitUtils.getCommit(repository,\r
"1d0c2933a4ae69c362f76797d42d6bd182d05176");\r
- String diff = DiffUtils.getCommitDiff(repository, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN).content;\r
+ String diff = DiffUtils.getCommitDiff(repository, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;\r
repository.close();\r
assertTrue(diff != null && diff.length() > 0);\r
String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";\r
"8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");\r
RevCommit commit = JGitUtils.getCommit(repository,\r
"1d0c2933a4ae69c362f76797d42d6bd182d05176");\r
- String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN).content;\r
+ String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;\r
repository.close();\r
assertTrue(diff != null && diff.length() > 0);\r
String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";\r
Repository repository = GitBlitSuite.getHelloworldRepository();\r
RevCommit commit = JGitUtils.getCommit(repository,\r
"1d0c2933a4ae69c362f76797d42d6bd182d05176");\r
- String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN).content;\r
+ String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffComparator.SHOW_WHITESPACE, DiffOutputType.PLAIN, 3).content;\r
repository.close();\r
assertTrue(diff != null && diff.length() > 0);\r
String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";\r
public void testEscapeForHtml() throws Exception {\r
String input = "& < > \" \t";\r
String outputNoChange = "& < > " \t";\r
- String outputChange = "& < > " ";\r
+ String outputChange = "& < > " ";\r
assertEquals(outputNoChange, StringUtils.escapeForHtml(input, false));\r
assertEquals(outputChange, StringUtils.escapeForHtml(input, true));\r
}\r