Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
erp5diff
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
erp5diff
Commits
fe64e381
Commit
fe64e381
authored
May 24, 2010
by
Nicolas Delaby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use better algorithm to compare two xml nodes.
parent
68726ed4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
24 deletions
+13
-24
ERP5Diff.py
ERP5Diff.py
+13
-24
No files found.
ERP5Diff.py
View file @
fe64e381
...
...
@@ -40,13 +40,17 @@ import zope.interface
class
FileContentNotEqual
(
Exception
):
pass
def
fileComparisonIterator
(
file1
,
file2
):
value1
=
file1
.
next
()
value2
=
file2
.
next
()
if
value1
==
value2
:
yield
value1
,
value2
else
:
raise
FileContentNotEqual
def
isNodeEquals
(
old
,
new
):
if
old
.
tag
!=
new
.
tag
or
old
.
attrib
!=
new
.
attrib
:
return
False
if
old
.
text
!=
new
.
text
or
old
.
tail
!=
new
.
tail
:
return
False
if
len
(
old
)
!=
len
(
new
):
return
False
for
old_child
,
new_child
in
zip
(
old
,
new
):
if
not
isNodeEquals
(
old_child
,
new_child
):
return
False
return
True
class
ERP5Diff
:
"""
...
...
@@ -481,27 +485,12 @@ class ERP5Diff:
for
old_index
,
old_element
in
enumerate
(
old_list
):
if
old_element
not
in
old_candidate_list
:
continue
old_tree
=
deepcopy
(
old_element
).
getroottree
()
old_c14n
=
StringIO
()
old_tree
.
write_c14n
(
old_c14n
)
old_c14n
.
seek
(
0
)
for
new_element
in
new_list
:
new_index
=
new_list
.
index
(
new_element
)
if
new_element
not
in
new_candidate_list
:
continue
new_tree
=
deepcopy
(
new_element
).
getroottree
()
new_c14n
=
StringIO
()
new_tree
.
write_c14n
(
new_c14n
)
new_c14n
.
seek
(
0
)
file_equality
=
True
try
:
#Use generator to avoid reading file entirely
#Stop iteration at first difference
list
(
fileComparisonIterator
(
old_c14n
,
new_c14n
))
except
FileContentNotEqual
:
file_equality
=
False
old_c14n
.
seek
(
0
)
if
file_equality
:
node_equality
=
isNodeEquals
(
old_element
,
new_element
)
if
node_equality
:
index_key_on_new_tree
=
new_element
.
getparent
().
index
(
new_element
)
old_new_index_mapping
[
index_key_on_new_tree
]
=
old_element
new_start
=
new_index
+
1
...
...
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