[diffoscope] 05/06: Distinguish between a full vs truncated set of pieces

Ximin Luo infinity0 at debian.org
Mon Sep 5 19:19:34 CEST 2016


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch better-lazy-loading
in repository diffoscope.

commit ead60c1efa0a0eea9c1beb875d6a14c331704c34
Author: Ximin Luo <infinity0 at debian.org>
Date:   Thu Aug 25 13:00:56 2016 +0200

    Distinguish between a full vs truncated set of pieces
---
 diffoscope/presenters/html.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/diffoscope/presenters/html.py b/diffoscope/presenters/html.py
index 1735a7f..248111c 100644
--- a/diffoscope/presenters/html.py
+++ b/diffoscope/presenters/html.py
@@ -168,8 +168,11 @@ SCRIPTS = """
 $(function() {
   var load_cont = function() {
     var a = $(this);
+    var textparts = /^(.*)\((\d+) pieces?(.*)\)$/.exec(a.text());
+    var numleft = Number.parseInt(textparts[2]) - 1;
+    var noun = numleft == 1 ? "piece" : "pieces";
+    var newtext = textparts[1] + "(" + numleft + " " + noun + textparts[3] + ")";
     var filename = a.attr('href');
-    var numleft = Number.parseInt(/\((\d+) pieces?\)/.exec(a.text())[1]) - 1
     var td = a.parent();
     td.text('... loading ...');
     td.parent().load(filename + " tr", function() {
@@ -177,8 +180,7 @@ $(function() {
         var elems = $(this).children(':first').unwrap();
         // set this behaviour for the next link too
         var a = elems.parent().find(".ondemand a");
-        var noun = numleft > 1 ? "pieces" : "piece" // be sure the regex matches either
-        a.text(a.text() + " (" + numleft + " " + noun + ")");
+        a.text(newtext);
         a.on('click', load_cont);
     });
     return false;
@@ -594,12 +596,14 @@ def output_unified_diff(print_func, css_url, directory, unified_diff, has_intern
         filename="%s.html" % mainname
         logger.debug('separate html output for diff of size %d', len(unified_diff))
         num_pages = 0
+        truncated = False
         rows_per_page = estimate_num_rows_per_page(Config.general.separate_file_diff_size)
         rotation_params = directory, mainname, css_url, rows_per_page
         try:
             spl_print_enter(spl_file_printer(directory, filename), rotation_params)
             output_unified_diff_table(unified_diff, has_internal_linenos)
         except PrintLimitReached:
+            truncated = True
             spl_print_func(u"<table><tr class='error'><td colspan='4'>Max output size reached.</td></tr></table>",
                            force=True)
             spl_print_exit(None, None, None) # swallow
@@ -610,8 +614,9 @@ def output_unified_diff(print_func, css_url, directory, unified_diff, has_intern
         finally:
             num_pages = spl_current_page + 1
 
+        text = "load diff (%s pieces%s)" % (num_pages, (", truncated" if truncated else ""))
         print_func(UD_TABLE_HEADER, force=True)
-        print_func(UD_TABLE_FOOTER % {"filename": html.escape(filename), "text": "load diff (%s pieces)" % num_pages}, force=True)
+        print_func(UD_TABLE_FOOTER % {"filename": html.escape(filename), "text": text}, force=True)
 
     else:
         try:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list