summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/utils/DiffUtils.java
diff options
context:
space:
mode:
authorTom <tw201207@gmail.com>2014-10-26 18:10:13 +0100
committerTom <tw201207@gmail.com>2014-11-06 18:05:33 +0100
commitdf0ba7f7ff02ed02c0ba7714ae928a79d932baef (patch)
treedaf72f5876cffec0b185276bd86a7060bd7f9391 /src/main/java/com/gitblit/utils/DiffUtils.java
parent02c6a8c24505625c5f411c0af1019c7c1f443d07 (diff)
downloadgitblit-df0ba7f7ff02ed02c0ba7714ae928a79d932baef.tar.gz
gitblit-df0ba7f7ff02ed02c0ba7714ae928a79d932baef.zip
Improve the commitdiff.
* Optimize CSS: simplify selectors. That alone cuts rendering time in half! * Adapt HTML generation accordingly. * Change line number generation so that one can select only code lines. Also move the +/- out of the code column; it also gets in the way when selecting. * Omit long diffs altogether. * Omit diff lines for deleted files, they're not particularly interesting. * Introduce a global limit on the maximum number of diff lines to show. * Supply translations for the languages I speak for the new messages. https://code.google.com/p/gitblit/issues/detail?id=450 was about a diff with nearly 300k changed lines (with more then 3000 files deleted). But one doesn't have to have such a monster commit to run into problems. My FF 32 become unresponsive for the 30+ seconds it takes it to render a commitdiff with some 30000 changed lines. (90% of which are in two generated files; the whole commit has just 20 files.) GitHub has no problems showing a commitdiff for this commit, but omits the two large generated files, which makes sense. This change implements a similar thing. Files with too many diff lines get omitted from the output, only the header and a message that the diff is too large remains. Additionally, there's a global limit on the length of a commitdiff; if we exceed that, the whole diff is truncated and the files not shown are listed. The CSS change improves performance by not using descendant selectors for all these table cells. Instead, we assign them precise classes and just use that in the CSS. The line number generation thing using data attributes and a :before selector in the CSS, which enables text selections only in the code column, is not strictly XHTML 1.0. (Data attributes are a feature of HTML 5.) However, reasonably modern browsers also handle this correctly if the page claims to be XHTML 1.0. Besides, the commitdiff page isn't XHTML compliant anyway; I don't think a pre-element may contain divs or even tables. (Note that this technique could be used on other diff pages, too. For instance on the blame page.)
Diffstat (limited to 'src/main/java/com/gitblit/utils/DiffUtils.java')
-rw-r--r--src/main/java/com/gitblit/utils/DiffUtils.java7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/main/java/com/gitblit/utils/DiffUtils.java b/src/main/java/com/gitblit/utils/DiffUtils.java
index dd2a7807..f597b946 100644
--- a/src/main/java/com/gitblit/utils/DiffUtils.java
+++ b/src/main/java/com/gitblit/utils/DiffUtils.java
@@ -228,15 +228,16 @@ public class DiffUtils {
DiffStat stat = null;
String diff = null;
try {
- final ByteArrayOutputStream os = new ByteArrayOutputStream();
+ ByteArrayOutputStream os = null;
RawTextComparator cmp = RawTextComparator.DEFAULT;
DiffFormatter df;
switch (outputType) {
case HTML:
- df = new GitBlitDiffFormatter(os, commit.getName());
+ df = new GitBlitDiffFormatter(commit.getName(), path);
break;
case PLAIN:
default:
+ os = new ByteArrayOutputStream();
df = new DiffFormatter(os);
break;
}
@@ -271,6 +272,7 @@ public class DiffUtils {
} else {
df.format(diffEntries);
}
+ df.flush();
if (df instanceof GitBlitDiffFormatter) {
// workaround for complex private methods in DiffFormatter
diff = ((GitBlitDiffFormatter) df).getHtml();
@@ -278,7 +280,6 @@ public class DiffUtils {
} else {
diff = os.toString();
}
- df.flush();
} catch (Throwable t) {
LOGGER.error("failed to generate commit diff!", t);
}