From 310a807f07ceeaa7d8fa0890d9061021707bbeb8 Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 22 May 2015 13:39:17 -0400 Subject: Implement configurable tab length support for blob views --- src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java') diff --git a/src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java b/src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java index 35549d4e..86b7ca2e 100644 --- a/src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java +++ b/src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java @@ -127,6 +127,8 @@ public class GitBlitDiffFormatter extends DiffFormatter { /** If {@link #truncated}, contains all entries skipped. */ private final List skipped = new ArrayList(); + 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; @@ -162,11 +164,12 @@ public class GitBlitDiffFormatter extends DiffFormatter { } - 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); @@ -453,14 +456,14 @@ public class GitBlitDiffFormatter extends DiffFormatter { // 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(""); result.append(StringUtils.escapeForHtml(matcher.group(1), false)); result.append(""); return result.toString(); } } - return StringUtils.escapeForHtml(line, CONVERT_TABS); + return StringUtils.escapeForHtml(line, CONVERT_TABS, tabLength); } /** @@ -493,7 +496,7 @@ public class GitBlitDiffFormatter extends DiffFormatter { } else { sb.append(""); } - line = StringUtils.escapeForHtml(line.substring(1), CONVERT_TABS); + line = StringUtils.escapeForHtml(line.substring(1), CONVERT_TABS, tabLength); } sb.append(line); if (gitLinkDiff) { -- cgit v1.2.3