Skip to content
GitLab
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
Reproducible Builds
diffoscope
Compare revisions
b7e1d092dccc4f4cf144746a187bd34b8d642cfc...b628a174e9720a2adb14ac23daa47c03b99a4e16
Commits (2)
Replace references to "WF" with Wagner-Fischer for clarity.
· 8329774c
Chris Lamb
authored
Jun 10, 2020
8329774c
Don't alias "filter" builtin.
· b628a174
Chris Lamb
authored
Jun 10, 2020
b628a174
Hide whitespace changes
Inline
Side-by-side
diffoscope/diff.py
View file @
b628a174
...
...
@@ -278,12 +278,12 @@ def empty_file_feeder():
return
feeder
def
make_feeder_from_raw_reader
(
in_file
,
filter
=
None
):
def
make_feeder_from_raw_reader
(
in_file
,
filter
fn
=
None
):
"""
Create a feeder that checksums, truncates, and transcodes the data. The
optional argument
FILTER
is a callable that gets passed each line, and
optional argument
filterfn
is a callable that gets passed each line, and
returns the line that should be used in its stead. (There is no facility
for
FILTER
to discard a line entirely.)
for
filterfn
to discard a line entirely.)
See _Feeder for feeders.
"""
...
...
@@ -299,7 +299,7 @@ def make_feeder_from_raw_reader(in_file, filter=None):
for
buf
in
in_file
:
line_count
+=
1
out
=
filter
(
buf
)
if
filter
else
buf
out
=
filter
fn
(
buf
)
if
filter
fn
else
buf
if
h
:
h
.
update
(
out
)
if
line_count
<
max_lines
:
...
...
@@ -384,7 +384,9 @@ def color_unified_diff(diff):
DIFFON
=
"
\x01
"
DIFFOFF
=
"
\x02
"
MAX_WF_SIZE
=
1024
# any higher, and linediff takes >1 second and >200MB RAM
MAX_WAGNER_FISCHER_SIZE
=
(
1024
# any higher, and linediff takes >1 second and >200MB RAM
)
def
_linediff_sane
(
x
):
...
...
@@ -404,7 +406,7 @@ def diffinput_truncate(s, sz):
def
linediff
(
s
,
t
,
diffon
,
diffoff
):
# calculate common prefix/suffix, easy optimisation
to WF
# calculate common prefix/suffix, easy optimisation
for Wagner-Fischer
prefix
=
os
.
path
.
commonprefix
((
s
,
t
))
if
prefix
:
s
=
s
[
len
(
prefix
)
:]
...
...
@@ -414,9 +416,9 @@ def linediff(s, t, diffon, diffoff):
s
=
s
[:
-
len
(
suffix
)]
t
=
t
[:
-
len
(
suffix
)]
# truncate so W
F
doesn't blow up RAM
s
=
diffinput_truncate
(
s
,
MAX_W
F
_SIZE
)
t
=
diffinput_truncate
(
t
,
MAX_W
F
_SIZE
)
# truncate so W
agner-Fischer
doesn't blow up RAM
s
=
diffinput_truncate
(
s
,
MAX_W
AGNER_FISCHER
_SIZE
)
t
=
diffinput_truncate
(
t
,
MAX_W
AGNER_FISCHER
_SIZE
)
l1
,
l2
=
zip
(
*
linediff_simplify
(
linediff_wagnerfischer
(
s
,
t
)))
def
to_string
(
k
,
v
):
...
...
@@ -487,7 +489,7 @@ def linediff_wagnerfischer(s, t):
def
linediff_simplify
(
g
):
"""Simplify the output of W
F
."""
"""Simplify the output of W
agner-Fischer
."""
current
=
None
for
l
,
r
in
g
:
if
not
current
:
...
...