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
345ed93b
Commit
345ed93b
authored
Feb 06, 2019
by
Vladislav Yarmak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement missing limit function
parent
375972f1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
6 deletions
+18
-6
win/tools/1337-diff/1337-diff.py
win/tools/1337-diff/1337-diff.py
+18
-6
No files found.
win/tools/1337-diff/1337-diff.py
View file @
345ed93b
...
...
@@ -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
:
...
...
@@ -81,19 +86,23 @@ def zip_files_bytes(left, right):
yield
a
,
b
def
diff
(
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
():
...
...
@@ -114,10 +123,13 @@ 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
,
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