[diffoscope] 01/01: comparators/deb: Looser matching for .deb archive members. (Closes: #881937)
Ximin Luo
infinity0 at debian.org
Wed Nov 29 17:07:04 CET 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository diffoscope.
commit e5dc438f3d4fabd91798b93f02e85810465f3c12
Author: Ximin Luo <infinity0 at debian.org>
Date: Wed Nov 29 17:03:28 2017 +0100
comparators/deb: Looser matching for .deb archive members. (Closes: #881937)
---
diffoscope/comparators/deb.py | 11 +++++++++++
diffoscope/comparators/utils/container.py | 5 ++++-
tests/comparators/test_deb.py | 12 ++++++++++++
tests/data/bug881937_1.deb | Bin 0 -> 1646 bytes
tests/data/bug881937_2.deb | Bin 0 -> 1716 bytes
tests/data/bug881937_control_expected_diff | 20 ++++++++++++++++++++
6 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/diffoscope/comparators/deb.py b/diffoscope/comparators/deb.py
index 7254219..7359dfe 100644
--- a/diffoscope/comparators/deb.py
+++ b/diffoscope/comparators/deb.py
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
+import os
import re
import logging
@@ -88,6 +89,16 @@ class DebContainer(LibarchiveContainer):
return specialize(member.as_container.get_member('content'))
+ def perform_fuzzy_matching(self, my_members, other_members):
+ matched = set()
+ for name1 in my_members.keys():
+ main, ext = os.path.splitext(name1)
+ candidates = [name2 for name2 in other_members.keys() - matched
+ if os.path.splitext(name2)[0] == main]
+ if len(candidates) == 1:
+ yield name1, candidates[0], 0
+ matched.add(candidates[0])
+
class DebFile(File):
CONTAINER_CLASS = DebContainer
diff --git a/diffoscope/comparators/utils/container.py b/diffoscope/comparators/utils/container.py
index e45faa7..a03aed9 100644
--- a/diffoscope/comparators/utils/container.py
+++ b/diffoscope/comparators/utils/container.py
@@ -79,6 +79,9 @@ class Container(object, metaclass=abc.ABCMeta):
for name in filter_excludes(self.get_member_names()):
yield name, self.get_member(name)
+ def perform_fuzzy_matching(self, my_members, other_members):
+ return perform_fuzzy_matching(my_members, other_members)
+
def get_adjusted_members(self):
"""
Returns an iterable of pairs. The key is what is used to match when
@@ -150,7 +153,7 @@ class Container(object, metaclass=abc.ABCMeta):
for name in both_names:
yield prep_yield(name, name)
- for my_name, other_name, score in perform_fuzzy_matching(my_members, other_members):
+ for my_name, other_name, score in self.perform_fuzzy_matching(my_members, other_members):
comment = "Files similar despite different names" \
" (difference score: {})".format(score)
yield prep_yield(my_name, other_name, comment)
diff --git a/tests/comparators/test_deb.py b/tests/comparators/test_deb.py
index 1cc8297..0746bc2 100644
--- a/tests/comparators/test_deb.py
+++ b/tests/comparators/test_deb.py
@@ -124,3 +124,15 @@ def test_compare_non_existing(monkeypatch, deb1):
difference = deb1.compare(MissingFile('/nonexisting', deb1))
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
+
+
+bug881937_deb1 = load_fixture('bug881937_1.deb')
+bug881937_deb2 = load_fixture('bug881937_2.deb')
+
+def test_compare_different_compression(bug881937_deb1, bug881937_deb2):
+ difference = bug881937_deb1.compare(bug881937_deb2)
+ assert difference.details[1].source1 == 'control.tar.gz'
+ assert difference.details[1].source2 == 'control.tar.xz'
+ expected_diff = get_data('bug881937_control_expected_diff')
+ assert difference.details[1].details[2].details[1].unified_diff == expected_diff
+
diff --git a/tests/data/bug881937_1.deb b/tests/data/bug881937_1.deb
new file mode 100644
index 0000000..91f33f6
Binary files /dev/null and b/tests/data/bug881937_1.deb differ
diff --git a/tests/data/bug881937_2.deb b/tests/data/bug881937_2.deb
new file mode 100644
index 0000000..e23d334
Binary files /dev/null and b/tests/data/bug881937_2.deb differ
diff --git a/tests/data/bug881937_control_expected_diff b/tests/data/bug881937_control_expected_diff
new file mode 100644
index 0000000..d3a3a13
--- /dev/null
+++ b/tests/data/bug881937_control_expected_diff
@@ -0,0 +1,20 @@
+@@ -1,16 +1,16 @@
+ Package: aptitude-robot
+-Version: 1.5.2-1
++Version: 1.5.3-1
+ Architecture: all
+ Maintainer: Elmar S. Heeb <elmar at heebs.ch>
+ Installed-Size: 85
+ Depends: aptitude, libmoo-perl, librun-parts-perl, lsb-base (>= 3.0-6), perl, psmisc
+ Recommends: perl-doc
+-Suggests: needrestart, needrestart-session, apt-listbugs, heirloom-mailx | bsd-mailx | mailx, xymon-client | hobbit-client
++Suggests: needrestart, needrestart-session, apt-listbugs, bsd-mailx | mailx, xymon-client | hobbit-client
+ Enhances: aptitude
+ Section: admin
+-Priority: extra
++Priority: optional
+ Homepage: https://github.com/elmar/aptitude-robot
+ Description: Automate package choice management
+ Framework to use aptitude for automated package management including
+ unattended upgrade, installation, removal, hold, etc. Allows you to automate
+ what you would manually do with aptitude.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list