Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
diffoscope
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reproducible Builds
diffoscope
Commits
341be077
Commit
341be077
authored
8 years ago
by
Ximin Luo
Browse files
Options
Downloads
Patches
Plain Diff
Suppress decimal line numbers for xxd output
parent
7e0cba03
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
diffoscope/comparators/binary.py
+3
-1
3 additions, 1 deletion
diffoscope/comparators/binary.py
diffoscope/difference.py
+9
-3
9 additions, 3 deletions
diffoscope/difference.py
diffoscope/presenters/html.py
+19
-13
19 additions, 13 deletions
diffoscope/presenters/html.py
with
31 additions
and
17 deletions
diffoscope/comparators/binary.py
+
3
−
1
View file @
341be077
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
diffoscope/difference.py
+
9
−
3
View file @
341be077
...
...
@@ -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!
'
)
...
...
@@ -390,6 +392,10 @@ class Difference(object):
def
unified_diff
(
self
):
return
self
.
_unified_diff
@property
def
has_internal_linenos
(
self
):
return
self
.
_has_internal_linenos
@property
def
details
(
self
):
return
self
.
_details
...
...
This diff is collapsed.
Click to expand it.
diffoscope/presenters/html.py
+
19
−
13
View file @
341be077
...
...
@@ -197,7 +197,7 @@ def create_limited_print_func(print_func, max_page_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
...
...
@@ -321,8 +321,7 @@ def output_hunk(print_func):
def
output_line
(
print_func
,
s1
,
s2
):
global
line1
global
line2
global
line1
,
line2
,
has_internal_linenos
orig1
=
s1
orig2
=
s2
...
...
@@ -349,16 +348,22 @@ def output_line(print_func, s1, s2):
print_func
(
u
'
<tr class=
"
diff%s
"
>
'
%
type_name
)
try
:
if
s1
:
print_func
(
u
'
<td class=
"
diffline
"
>%d </td>
'
%
line1
)
print_func
(
u
'
<td class=
"
diffpresent
"
>
'
)
if
has_internal_linenos
:
print_func
(
u
'
<td colspan=
"
2
"
class=
"
diffpresent
"
>
'
)
else
:
print_func
(
u
'
<td class=
"
diffline
"
>%d </td>
'
%
line1
)
print_func
(
u
'
<td class=
"
diffpresent
"
>
'
)
print_func
(
convert
(
s1
,
ponct
=
1
,
tag
=
'
del
'
))
print_func
(
u
'
</td>
'
)
else
:
print_func
(
u
'
<td colspan=
"
2
"
>
\xa0
</td>
'
)
if
s2
:
print_func
(
u
'
<td class=
"
diffline
"
>%d </td>
'
%
line2
)
print_func
(
u
'
<td class=
"
diffpresent
"
>
'
)
if
has_internal_linenos
:
print_func
(
u
'
<td colspan=
"
2
"
class=
"
diffpresent
"
>
'
)
else
:
print_func
(
u
'
<td class=
"
diffline
"
>%d </td>
'
%
line2
)
print_func
(
u
'
<td class=
"
diffpresent
"
>
'
)
print_func
(
convert
(
s2
,
ponct
=
1
,
tag
=
'
ins
'
))
print_func
(
u
'
</td>
'
)
else
:
...
...
@@ -407,11 +412,12 @@ def empty_buffer(print_func):
buf
=
[]
def
output_unified_diff_table
(
print_func
,
unified_diff
):
def
output_unified_diff_table
(
print_func
,
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
print_func
(
u
'
<table class=
"
diff
"
>
\n
'
)
try
:
print_func
(
u
'
<colgroup><col style=
"
width: 3em;
"
/><col style=
"
99%
"
/>
\n
'
)
...
...
@@ -490,14 +496,14 @@ def output_unified_diff_table(print_func, unified_diff):
finally
:
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
):
if
directory
and
len
(
unified_diff
)
>
Config
.
general
.
separate_file_diff_size
:
# open a new file for this table
filename
=
"
%s.html
"
%
hashlib
.
md5
(
unified_diff
.
encode
(
'
utf-8
'
)).
hexdigest
()
logger
.
debug
(
'
separate html output for diff of size %d
'
,
len
(
unified_diff
))
with
file_printer
(
directory
,
filename
)
as
new_print_func
:
output_header
(
css_url
,
new_print_func
)
output_unified_diff_table
(
new_print_func
,
unified_diff
)
output_unified_diff_table
(
new_print_func
,
unified_diff
,
has_internal_linenos
)
output_footer
(
new_print_func
)
print_func
(
"
<div class=
'
ondemand
'
>
\n
"
)
...
...
@@ -505,7 +511,7 @@ def output_unified_diff(print_func, css_url, directory, unified_diff):
print_func
(
"
</div>
\n
"
)
else
:
output_unified_diff_table
(
print_func
,
unified_diff
)
output_unified_diff_table
(
print_func
,
unified_diff
,
has_internal_linenos
)
def
output_difference
(
difference
,
print_func
,
css_url
,
directory
,
parents
):
logger
.
debug
(
'
html output for %s
'
,
difference
.
source1
)
...
...
@@ -529,7 +535,7 @@ def output_difference(difference, print_func, css_url, directory, parents):
%
u
'
<br />
'
.
join
(
map
(
html
.
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
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment