[diffoscope] 01/01: Unbreak the single html output
Ximin Luo
infinity0 at debian.org
Wed Aug 24 20:57:47 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 4d2f611cd060629ac35620f47b6e07edf6528290
Author: Ximin Luo <infinity0 at debian.org>
Date: Wed Aug 24 20:57:01 2016 +0200
Unbreak the single html output
We don't need to call row_print_enter because someone else owns print_func and
is responsible for cleaning up after it
---
diffoscope/presenters/html.py | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/diffoscope/presenters/html.py b/diffoscope/presenters/html.py
index 5968860..40d7b7f 100644
--- a/diffoscope/presenters/html.py
+++ b/diffoscope/presenters/html.py
@@ -449,9 +449,12 @@ def row_print_exit_else():
row_print_func, row_print_ctrl = None, None
row_print_exit(None, None, None)
+
def row_was_output():
global row_print_func, row_print_ctrl, rows_output, diff_table_current_page
rows_output += 1
+ if not row_print_ctrl:
+ return
_, rotation_params = row_print_ctrl
directory, mainname, css_url, rows_per_page = rotation_params
if rows_output % rows_per_page != 0:
@@ -474,17 +477,6 @@ def row_was_output():
row_print_func(u'<colgroup><col style="width: 3em;"/><col style="99%"/>\n')
row_print_func(u'<col style="width: 3em;"/><col style="99%"/></colgroup>\n')
- at contextlib.contextmanager
-def global_row_printer(print_context, rotation_params=None):
- """Context manager that allows the context to be changed during the body."""
- try:
- row_print_enter(print_context, rotation_params)
- yield row_print_func
- except:
- if not row_print_exit_exc():
- raise
- else:
- row_print_exit_else()
def output_unified_diff_table(unified_diff):
global add_cpt, del_cpt
@@ -569,29 +561,40 @@ def output_unified_diff_table(unified_diff):
finally:
row_print_func(u"</table>", force=True)
+
def output_unified_diff(print_func, css_url, directory, unified_diff):
+ global row_print_func, diff_table_current_page
if directory and len(unified_diff) > Config.general.separate_file_diff_size:
# open a new file for this table
mainname = hashlib.md5(unified_diff.encode('utf-8')).hexdigest()
filename="%s.html" % mainname
logger.debug('separate html output for diff of size %d', len(unified_diff))
num_pages = 0
- global row_print_func, diff_table_current_page
rows_per_page = estimate_num_rows_per_page(Config.general.separate_file_diff_size)
rotation_params = directory, mainname, css_url, rows_per_page
- with global_row_printer(file_printer(directory, filename), rotation_params):
+ try:
+ row_print_enter(file_printer(directory, filename), rotation_params)
output_header(css_url, row_print_func)
output_unified_diff_table(unified_diff)
output_footer(row_print_func)
num_pages = diff_table_current_page + 1
+ except:
+ if not row_print_exit_exc():
+ raise
+ else:
+ row_print_exit_else()
print_func("<div class='ondemand'>\n")
print_func("... <a href='%s'>load diff (%s pieces) </a> ...\n" % (escape(filename), num_pages))
print_func("</div>\n")
else:
- with global_row_printer(print_func):
+ try:
+ row_print_func = print_func
output_unified_diff_table(unified_diff)
+ finally:
+ row_print_func = None
+
def output_difference(difference, print_func, css_url, directory, parents):
logger.debug('html output for %s', difference.source1)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list