Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
nvidia-patch
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
nvidia-patch
Commits
5adcc24a
Commit
5adcc24a
authored
Feb 06, 2019
by
Vladislav Yarmak
Committed by
GitHub
Feb 06, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #49 from Snawoot/1337-diff-improvements
1337-diff improvements
parents
0fa7df74
6e5d608b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
12 deletions
+33
-12
win/tools/1337-diff/1337-diff.py
win/tools/1337-diff/1337-diff.py
+33
-12
No files found.
win/tools/1337-diff/1337-diff.py
View file @
5adcc24a
...
...
@@ -22,6 +22,11 @@ class LengthMismatchException(ByteDiffException):
pass
class
DiffLimitException
(
ByteDiffException
):
""" Throwed when difference limit hit """
pass
def
check_positive_int
(
value
):
value
=
int
(
value
)
if
value
<=
0
:
...
...
@@ -64,31 +69,43 @@ def feed_chunks(f, chunk_size=4096):
yield
buf
def
zip_files_bytes
(
*
files
):
def
zip_files_bytes
(
left
,
right
):
""" Iterate over two files, returning pair of bytes.
Throw LengthMismatch if file sizes is uneven. """
class
EndMarker
(
object
):
pass
end_marker
=
EndMarker
()
iterators
=
(
itertools
.
chain
.
from_iterable
(
feed_chunks
(
f
))
for
f
in
files
)
for
tup
in
itertools
.
zip_longest
(
*
iterators
,
fillvalue
=
end_marker
):
if
any
(
v
is
end_marker
for
v
in
tup
):
left_iter
=
itertools
.
chain
.
from_iterable
(
feed_chunks
(
left
))
right_iter
=
itertools
.
chain
.
from_iterable
(
feed_chunks
(
right
))
for
a
,
b
in
itertools
.
zip_longest
(
left_iter
,
right_iter
,
fillvalue
=
end_marker
):
if
a
is
end_marker
or
b
is
end_marker
:
raise
LengthMismatchException
(
"Length of input files inequal."
)
yield
tup
yield
a
,
b
def
diff
(
left
,
right
):
for
offset
,
(
a
,
b
)
in
enumerate
(
zip_files_bytes
(
left
,
right
)):
def
diff
(
left
,
right
,
limit
=
None
):
offset
=
0
diff_count
=
0
for
a
,
b
in
zip_files_bytes
(
left
,
right
):
if
a
!=
b
:
diff_count
+=
1
if
limit
is
not
None
and
diff_count
>
limit
:
raise
DiffLimitException
()
yield
offset
,
a
,
b
offset
+=
1
def
compose_diff_file
(
orig
,
patched
,
output
,
header
,
offset_adjustment
=
True
):
def
compose_diff_file
(
orig
,
patched
,
output
,
header
,
*
,
limit
=
None
,
offset_adjustment
=
True
):
output
.
write
(
HEADER_FORMAT
%
(
header
.
encode
(
'latin-1'
),))
for
offset
,
a
,
b
in
diff
(
orig
,
patched
):
o
=
offset
+
OFFSET_ADJUSTMENT
if
offset_adjustment
else
offset
output
.
write
(
LINE_FORMAT
%
(
o
,
a
,
b
))
adj
=
OFFSET_ADJUSTMENT
if
offset_adjustment
else
0
for
offset
,
a
,
b
in
diff
(
orig
,
patched
,
limit
):
output
.
write
(
LINE_FORMAT
%
(
o
ffset
+
adj
,
a
,
b
))
def
main
():
...
...
@@ -109,10 +126,14 @@ def main():
open
(
args
.
patched_file
,
'rb'
)
as
patched
,
\
open
(
output_filename
,
'wb'
)
as
output
:
try
:
compose_diff_file
(
orig
,
patched
,
output
,
header_filename
)
compose_diff_file
(
orig
,
patched
,
output
,
header_filename
,
limit
=
args
.
limit
)
except
LengthMismatchException
:
print
(
"Input files have inequal length. Aborting..."
,
file
=
sys
.
stderr
)
except
DiffLimitException
:
print
(
"Differences limit hit. Aborting..."
,
file
=
sys
.
stderr
)
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment