From eb849230e8d258109230613c0725d29898c45a96 Mon Sep 17 00:00:00 2001
From: Maria Glukhova <siamezzze@gmail.com>
Date: Mon, 6 Mar 2017 06:03:27 +0200
Subject: [PATCH 2/2] Indicate the AndroidManifest.xml type.

Show the decoded/undecoded type of AndroidManifest.xml file.

Closes: #850758
---
 diffoscope/comparators/apk.py           |  8 ++++++--
 diffoscope/comparators/utils/compare.py |  4 +++-
 tests/comparators/test_apk.py           | 14 ++++++++++----
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/diffoscope/comparators/apk.py b/diffoscope/comparators/apk.py
index fc0b5f1..cd3ef21 100644
--- a/diffoscope/comparators/apk.py
+++ b/diffoscope/comparators/apk.py
@@ -116,8 +116,10 @@ class ApkContainer(Archive):
         comment = None
         diff_manifests = None
         if my_android_manifest and other_android_manifest:
+            source = 'AndroidManifest.xml (decoded)'
             diff_manifests = compare_files(my_android_manifest,
-                                           other_android_manifest)
+                                           other_android_manifest,
+                                           source=source)
             if diff_manifests is None:
                 comment = 'No difference found for decoded AndroidManifest.xml'
         else:
@@ -126,8 +128,10 @@ class ApkContainer(Archive):
         if diff_manifests:
             return diff_manifests
 
+        source = 'AndroidManifest.xml (original / undecoded)'
         diff_manifests = compare_files(self.get_original_android_manifest(),
-                                       other.get_original_android_manifest())
+                                       other.get_original_android_manifest(),
+                                       source=source)
         if diff_manifests is not None:
             diff_manifests.add_comment(comment)
         return diff_manifests
diff --git a/diffoscope/comparators/utils/compare.py b/diffoscope/comparators/utils/compare.py
index b069a0e..4259409 100644
--- a/diffoscope/comparators/utils/compare.py
+++ b/diffoscope/comparators/utils/compare.py
@@ -107,9 +107,11 @@ def bail_if_non_existing(*paths):
 
 def compare_binary_files(file1, file2, source=None):
     try:
+        if source is None:
+            source = [file1.name, file2.name]
         return Difference.from_command(
             Xxd, file1.path, file2.path,
-            source=[file1.name, file2.name], has_internal_linenos=True)
+            source=source, has_internal_linenos=True)
     except RequiredToolNotFound:
         hexdump1 = hexdump_fallback(file1.path)
         hexdump2 = hexdump_fallback(file2.path)
diff --git a/tests/comparators/test_apk.py b/tests/comparators/test_apk.py
index 27c46e8..ef68c6e 100644
--- a/tests/comparators/test_apk.py
+++ b/tests/comparators/test_apk.py
@@ -52,8 +52,8 @@ def test_zipinfo(differences):
 
 @skip_unless_tools_exist('apktool', 'zipinfo')
 def test_android_manifest(differences):
-    assert differences[1].source1 == 'AndroidManifest.xml'
-    assert differences[1].source2 == 'AndroidManifest.xml'
+    assert differences[1].source1 == 'AndroidManifest.xml (decoded)'
+    assert differences[1].source2 == 'AndroidManifest.xml (decoded)'
     expected_diff = get_data('apk_manifest_expected_diff')
     assert differences[1].unified_diff == expected_diff
 
@@ -64,5 +64,11 @@ def test_apk_metadata_source(differences):
 
 @skip_unless_tools_exist('apktool', 'zipinfo')
 def test_skip_undecoded_android_manifest(differences):
-    assert not any(difference.source1 == 'original/AndroidManifest.xml' for difference in differences)
-    assert not any(difference.source2 == 'original/AndroidManifest.xml' for difference in differences)
+    assert not any(difference.source1 == 'original/AndroidManifest.xml' for
+                   difference in differences)
+    assert not any(difference.source2 == 'original/AndroidManifest.xml' for
+                   difference in differences)
+    assert not any(difference.source1 == 'AndroidManifest.xml (original / undecoded)' for
+                   difference in differences)
+    assert not any(difference.source2 == 'AndroidManifest.xml (original / undecoded)' for
+                   difference in differences)
-- 
2.11.0

