From c2188a840bc4153ae92112b04b2e06a90d3944aa Mon Sep 17 00:00:00 2001 From: Paul Martin <paul@paulsputer.com> Date: Wed, 27 Apr 2016 18:58:06 -0400 Subject: [PATCH] Ticket Reference handling #1048 --- src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java | 21 ++++++++++++++------- 1 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java b/src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java index edaed70..8ebadbf 100644 --- a/src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java +++ b/src/main/java/com/gitblit/utils/GitBlitDiffFormatter.java @@ -33,6 +33,7 @@ import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.diff.DiffFormatter; import org.eclipse.jgit.diff.RawText; +import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.util.RawParseUtils; import com.gitblit.models.PathModel.PathChangeModel; @@ -73,6 +74,8 @@ * through gitblit.properties key {@link #GLOBAL_DIFF_LIMIT_KEY}. */ private static final int GLOBAL_DIFF_LIMIT = 20000; + + private static final boolean CONVERT_TABS = true; private final DiffOutputStream os; @@ -125,6 +128,8 @@ /** 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; @@ -150,7 +155,7 @@ { String binaryDiff = binaryDiffHandler.renderBinaryDiff(formatter.entry); if (binaryDiff != null) { - byte[] bb = ("<tr><td colspan='4'>" + binaryDiff + "</td></tr>").getBytes(StandardCharsets.UTF_8); + byte[] bb = ("<tr><td colspan='4' align='center'>" + binaryDiff + "</td></tr>").getBytes(StandardCharsets.UTF_8); super.write(bb, 0, bb.length); return; } @@ -160,11 +165,12 @@ } - public GitBlitDiffFormatter(String commitId, String path, BinaryDiffHandler handler) { + public GitBlitDiffFormatter(String commitId, Repository repository, String path, BinaryDiffHandler handler, int tabLength) { super(new DiffOutputStream()); this.os = (DiffOutputStream) getOutputStream(); this.os.setFormatter(this, handler); - this.diffStat = new DiffStat(commitId); + this.diffStat = new DiffStat(commitId, repository); + 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); @@ -451,14 +457,14 @@ // 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()), false)); + 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, false); + return StringUtils.escapeForHtml(line, CONVERT_TABS, tabLength); } /** @@ -471,7 +477,8 @@ String[] lines = html.split("\n"); StringBuilder sb = new StringBuilder(); for (String line : lines) { - if (line.startsWith("index")) { + if (line.startsWith("index") || line.startsWith("similarity") + || line.startsWith("rename from ") || line.startsWith("rename to ")) { // skip index lines } else if (line.startsWith("new file") || line.startsWith("deleted file")) { // skip new file lines @@ -490,7 +497,7 @@ } else { sb.append("<th class='diff-state diff-state-sub'></th><td class=\"diff-cell remove2\">"); } - line = StringUtils.escapeForHtml(line.substring(1), false); + line = StringUtils.escapeForHtml(line.substring(1), CONVERT_TABS, tabLength); } sb.append(line); if (gitLinkDiff) { -- Gitblit v1.9.1