[diffoscope] 04/04: Suppress decimal line numbers for xxd output
Ximin Luo
infinity0 at debian.org
Thu Aug 25 12:23:58 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 eb157bfcd22e567926df93be2c36c3e9ad7a86d6
Author: Ximin Luo <infinity0 at debian.org>
Date: Thu Aug 25 02:31:37 2016 +0200
Suppress decimal line numbers for xxd output
---
diffoscope/comparators/binary.py | 4 +++-
diffoscope/difference.py | 12 +++++++++---
diffoscope/presenters/html.py | 32 +++++++++++++++++++-------------
3 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/diffoscope/comparators/binary.py b/diffoscope/comparators/binary.py
index 55b152e..a72ad6f 100644
--- a/diffoscope/comparators/binary.py
+++ b/diffoscope/comparators/binary.py
@@ -56,7 +56,9 @@ def compare_binary_files(file1, file2, source=None):
import diffoscope.comparators.utils
try:
- return Difference.from_command(diffoscope.comparators.utils.Xxd, file1.path, file2.path, source=[file1.name, file2.name])
+ return Difference.from_command(
+ diffoscope.comparators.utils.Xxd, file1.path, file2.path,
+ source=[file1.name, file2.name], has_internal_linenos=True)
except RequiredToolNotFound:
hexdump1 = hexdump_fallback(file1.path)
hexdump2 = hexdump_fallback(file2.path)
diff --git a/diffoscope/difference.py b/diffoscope/difference.py
index b2ed8a7..edffc72 100644
--- a/diffoscope/difference.py
+++ b/diffoscope/difference.py
@@ -273,7 +273,7 @@ def diff(feeder1, feeder2):
class Difference(object):
- def __init__(self, unified_diff, path1, path2, source=None, comment=None):
+ def __init__(self, unified_diff, path1, path2, source=None, comment=None, has_internal_linenos=False):
self._comments = []
if comment:
if type(comment) is list:
@@ -297,18 +297,20 @@ class Difference(object):
raise TypeError("path1/source[0] is not a string")
if not isinstance(self._source2, str):
raise TypeError("path2/source[1] is not a string")
+ # Whether the unified_diff already contains line numbers inside itself
+ self._has_internal_linenos = has_internal_linenos
self._details = []
def __repr__(self):
return '<Difference %s -- %s %s>' % (self._source1, self._source2, self._details)
@staticmethod
- def from_feeder(feeder1, feeder2, path1, path2, source=None, comment=None):
+ def from_feeder(feeder1, feeder2, path1, path2, source=None, comment=None, **kwargs):
try:
unified_diff = diff(feeder1, feeder2)
if not unified_diff:
return None
- return Difference(unified_diff, path1, path2, source, comment)
+ return Difference(unified_diff, path1, path2, source, comment, **kwargs)
except RequiredToolNotFound:
difference = Difference(None, path1, path2, source)
difference.add_comment('diff is not available!')
@@ -391,6 +393,10 @@ class Difference(object):
return self._unified_diff
@property
+ def has_internal_linenos(self):
+ return self._has_internal_linenos
+
+ @property
def details(self):
return self._details
diff --git a/diffoscope/presenters/html.py b/diffoscope/presenters/html.py
index 3450d20..2470707 100644
--- a/diffoscope/presenters/html.py
+++ b/diffoscope/presenters/html.py
@@ -223,7 +223,7 @@ def estimate_num_rows_per_page(separate_file_diff_size):
buf, add_cpt, del_cpt = [], 0, 0
-line1, line2 = 0, 0
+line1, line2, has_internal_linenos = 0, 0, True
hunk_off1, hunk_size1, hunk_off2, hunk_size2 = 0, 0, 0, 0
spl_rows, spl_bytes, spl_current_page = 0, 0, 0
spl_print_func, spl_print_ctrl = None, None
@@ -363,8 +363,7 @@ def output_hunk():
def output_line(s1, s2):
- global line1
- global line2
+ global line1, line2, has_internal_linenos
orig1 = s1
orig2 = s2
@@ -391,16 +390,22 @@ def output_line(s1, s2):
spl_print_func(u'<tr class="diff%s">' % type_name)
try:
if s1:
- spl_print_func(u'<td class="diffline">%d </td>' % line1)
- spl_print_func(u'<td class="diffpresent">')
+ if has_internal_linenos:
+ spl_print_func(u'<td colspan="2" class="diffpresent">')
+ else:
+ spl_print_func(u'<td class="diffline">%d </td>' % line1)
+ spl_print_func(u'<td class="diffpresent">')
spl_print_func(convert(s1, ponct=1, tag='del'))
spl_print_func(u'</td>')
else:
spl_print_func(u'<td colspan="2">\xa0</td>')
if s2:
- spl_print_func(u'<td class="diffline">%d </td>' % line2)
- spl_print_func(u'<td class="diffpresent">')
+ if has_internal_linenos:
+ spl_print_func(u'<td colspan="2" class="diffpresent">')
+ else:
+ spl_print_func(u'<td class="diffline">%d </td>' % line2)
+ spl_print_func(u'<td class="diffpresent">')
spl_print_func(convert(s2, ponct=1, tag='ins'))
spl_print_func(u'</td>')
else:
@@ -500,11 +505,12 @@ def row_was_output():
spl_print_func(UD_TABLE_HEADER)
-def output_unified_diff_table(unified_diff):
+def output_unified_diff_table(unified_diff, _has_internal_linenos):
global add_cpt, del_cpt
- global line1, line2
+ global line1, line2, has_internal_linenos
global hunk_off1, hunk_size1, hunk_off2, hunk_size2
+ has_internal_linenos = _has_internal_linenos
spl_print_func(UD_TABLE_HEADER)
try:
for l in unified_diff.splitlines():
@@ -581,7 +587,7 @@ def output_unified_diff_table(unified_diff):
spl_print_func(u"</table>", force=True)
-def output_unified_diff(print_func, css_url, directory, unified_diff):
+def output_unified_diff(print_func, css_url, directory, unified_diff, has_internal_linenos):
global spl_print_func, spl_current_page
new_unified_diff()
if directory and len(unified_diff) > Config.general.separate_file_diff_size:
@@ -594,7 +600,7 @@ def output_unified_diff(print_func, css_url, directory, unified_diff):
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)
+ output_unified_diff_table(unified_diff, has_internal_linenos)
except PrintLimitReached:
spl_print_func(u"<table><tr class='error'><td colspan='4'>Max output size reached.</td></tr></table>",
force=True)
@@ -612,7 +618,7 @@ def output_unified_diff(print_func, css_url, directory, unified_diff):
else:
try:
spl_print_func = print_func
- output_unified_diff_table(unified_diff)
+ output_unified_diff_table(unified_diff, has_internal_linenos)
finally:
spl_print_func = None
@@ -639,7 +645,7 @@ def output_difference(difference, print_func, css_url, directory, parents):
% u'<br />'.join(map(escape, difference.comments)))
print_func(u"</div>")
if difference.unified_diff:
- output_unified_diff(print_func, css_url, directory, difference.unified_diff)
+ output_unified_diff(print_func, css_url, directory, difference.unified_diff, difference.has_internal_linenos)
for detail in difference.details:
output_difference(detail, print_func, css_url, directory, sources)
except PrintLimitReached:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list