[Git][reproducible-builds/diffoscope][master] Difference.__init__: demote unified_diff to kwarg
Chris Lamb
gitlab at salsa.debian.org
Fri Apr 9 07:47:07 UTC 2021
Chris Lamb pushed to branch master at Reproducible Builds / diffoscope
Commits:
a3bfba06 by Zachary T Welch at 2021-04-08T17:09:37-07:00
Difference.__init__: demote unified_diff to kwarg
- - - - -
16 changed files:
- diffoscope/comparators/decompile.py
- diffoscope/comparators/directory.py
- diffoscope/comparators/gif.py
- diffoscope/comparators/gnumeric.py
- diffoscope/comparators/missing_file.py
- diffoscope/comparators/png.py
- diffoscope/comparators/text.py
- diffoscope/comparators/utils/compare.py
- diffoscope/comparators/utils/container.py
- diffoscope/comparators/utils/file.py
- diffoscope/comparators/xml.py
- diffoscope/difference.py
- diffoscope/main.py
- diffoscope/readers/json.py
- tests/comparators/test_binary.py
- tests/test_difference.py
Changes:
=====================================
diffoscope/comparators/decompile.py
=====================================
@@ -226,7 +226,7 @@ class AsmFunction(File):
if not details:
return None
- difference = Difference(None, self.name, other.name, source=source)
+ difference = Difference(self.name, other.name, source=source)
difference.add_details(details)
return difference
=====================================
diffoscope/comparators/directory.py
=====================================
@@ -287,7 +287,7 @@ class FilesystemDirectory(Directory):
if not differences:
return None
- difference = Difference(None, self.path, other.path, source)
+ difference = Difference(self.path, other.path, source)
difference.add_details(differences)
return difference
=====================================
diffoscope/comparators/gif.py
=====================================
@@ -88,7 +88,7 @@ class GifFile(File):
other.path,
)
content_diff = Difference(
- None, self.path, other.path, source="Image content"
+ self.path, other.path, source="Image content"
)
content_diff.add_visuals(
[
=====================================
diffoscope/comparators/gnumeric.py
=====================================
@@ -36,7 +36,6 @@ class GnumericFile(File):
if isinstance(other, MissingFile):
return [
Difference(
- None,
self.name,
other.name,
comment="Trying to compare two non-existing files.",
=====================================
diffoscope/comparators/missing_file.py
=====================================
@@ -80,7 +80,6 @@ class MissingFile(File, AbstractMissingType):
# lies) and and then reverse it.
if isinstance(other, MissingFile):
return Difference(
- None,
self.name,
other.name,
comment="Trying to compare two non-existing files.",
=====================================
diffoscope/comparators/png.py
=====================================
@@ -66,7 +66,7 @@ class PngFile(File):
other.path,
)
content_diff = Difference(
- None, self.path, other.path, source="Image content"
+ self.path, other.path, source="Image content"
)
content_diff.add_visuals(
[
=====================================
diffoscope/comparators/text.py
=====================================
@@ -49,9 +49,7 @@ class TextFile(File):
)
if my_encoding != other_encoding:
if difference is None:
- difference = Difference(
- None, self.path, other.path, source
- )
+ difference = Difference(self.path, other.path, source)
difference.add_details(
[
Difference.from_text(
=====================================
diffoscope/comparators/utils/compare.py
=====================================
@@ -74,7 +74,7 @@ def compare_root_paths(path1, path2):
# Create an "empty" difference so we have something to attach file
# metadata to.
if difference is None:
- difference = Difference(None, file1.name, file2.name)
+ difference = Difference(file1.name, file2.name)
difference.add_details(meta)
return difference
@@ -109,7 +109,7 @@ def compare_files(file1, file2, source=None, diff_content_only=False):
if diff_content_only:
return None
elif diff_content_only:
- return Difference(None, file1.name, file2.name, comment="Files differ")
+ return Difference(file1.name, file2.name, comment="Files differ")
call_difftool(file1, file2)
=====================================
diffoscope/comparators/utils/container.py
=====================================
@@ -202,13 +202,13 @@ class Container(metaclass=abc.ABCMeta):
meta_differences = compare_meta(file1.name, file2.name)
if meta_differences and not difference:
- difference = Difference(None, file1.path, file2.path)
+ difference = Difference(file1.path, file2.path)
if difference:
difference.add_details(meta_differences)
if comment:
if difference is None:
- difference = Difference(None, file1.name, file2.name)
+ difference = Difference(file1.name, file2.name)
difference.add_comment(comment)
return difference
=====================================
diffoscope/comparators/utils/file.py
=====================================
@@ -395,7 +395,7 @@ class File(metaclass=abc.ABCMeta):
def _compare_using_details(self, other, source):
details = []
- difference = Difference(None, self.name, other.name, source=source)
+ difference = Difference(self.name, other.name, source=source)
if hasattr(self, "compare_details"):
details.extend(self.compare_details(other, source))
=====================================
diffoscope/comparators/xml.py
=====================================
@@ -121,7 +121,6 @@ class XMLFile(File):
if isinstance(other, MissingFile):
return [
Difference(
- None,
self.name,
other.name,
comment="Trying to compare two non-existing files.",
=====================================
diffoscope/difference.py
=====================================
@@ -33,7 +33,6 @@ logger = logging.getLogger(__name__)
class Difference:
def __init__(
self,
- unified_diff,
path1,
path2,
source=None,
@@ -41,6 +40,7 @@ class Difference:
has_internal_linenos=False,
details=None,
visuals=None,
+ unified_diff=None,
):
self._unified_diff = unified_diff
@@ -84,10 +84,9 @@ class Difference:
def map_lines(self, f_diff, f_comment):
unified_diff = self.unified_diff
+ if unified_diff is not None:
+ unified_diff = "".join(map(f_diff, diff_split_lines(unified_diff)))
return self.__class__(
- "".join(map(f_diff, diff_split_lines(unified_diff)))
- if unified_diff is not None
- else None,
self.source1,
self.source2,
comment=[
@@ -97,18 +96,19 @@ class Difference:
has_internal_linenos=self.has_internal_linenos,
details=self._details[:],
visuals=self._visuals[:],
+ unified_diff=unified_diff,
)
def fmap(self, f):
return f(
self.__class__(
- self.unified_diff,
self.source1,
self.source2,
comment=self._comments[:],
has_internal_linenos=self.has_internal_linenos,
details=[d.fmap(f) for d in self._details],
visuals=self._visuals[:],
+ unified_diff=self.unified_diff,
)
)
@@ -118,15 +118,18 @@ class Difference:
raise NotImplementedError(
"_reverse_self on VisualDifference is not yet implemented"
)
- return self.__class__(
+ unified_diff = (
reverse_unified_diff(self.unified_diff)
if self.unified_diff is not None
- else None,
+ else None
+ )
+ return self.__class__(
self.source2,
self.source1,
comment=self._comments, # already copied by fmap in get_reverse
has_internal_linenos=self.has_internal_linenos,
details=self._details, # already reversed by fmap in get_reverse, no need to copy
+ unified_diff=unified_diff,
)
def get_reverse(self):
@@ -214,10 +217,15 @@ class Difference:
if not unified_diff:
return None
return Difference(
- unified_diff, path1, path2, source, comment, **kwargs
+ path1,
+ path2,
+ source,
+ comment,
+ unified_diff=unified_diff,
+ **kwargs,
)
except RequiredToolNotFound:
- difference = Difference(None, path1, path2, source)
+ difference = Difference(path1, path2, source)
difference.add_comment("diff is not available")
if comment:
difference.add_comment(comment)
@@ -369,6 +377,10 @@ class Difference:
def unified_diff(self):
return self._unified_diff
+ @unified_diff.setter
+ def unified_diff(self, value):
+ self._unified_diff = value
+
@property
def has_internal_linenos(self):
return self._has_internal_linenos
=====================================
diffoscope/main.py
=====================================
@@ -702,7 +702,7 @@ def run_diffoscope(parsed_args):
# Generate an empty, null diff to write, saving the exit code first.
has_differences = bool(difference is not None)
if difference is None and parsed_args.output_empty:
- difference = Difference(None, path1, path2)
+ difference = Difference(path1, path2)
with profile("main", "outputs"):
PresenterManager().output(difference, parsed_args, has_differences)
return 1 if has_differences else 0
=====================================
diffoscope/readers/json.py
=====================================
@@ -44,5 +44,9 @@ class JSONReaderV1:
details = [self.load_rec(child) for child in raw.get("details", [])]
return Difference(
- unified_diff, source1, source2, comment=comments, details=details
+ source1,
+ source2,
+ comment=comments,
+ details=details,
+ unified_diff=unified_diff,
)
=====================================
tests/comparators/test_binary.py
=====================================
@@ -112,7 +112,7 @@ def test_compare_without_xxd(xxd_not_found, binary1, binary2):
def test_with_compare_details():
- d = Difference("diff", TEST_FILE1_PATH, TEST_FILE2_PATH, source="source")
+ d = Difference(TEST_FILE1_PATH, TEST_FILE2_PATH, source="source")
class MockFile(FilesystemFile):
def compare_details(self, other, source=None):
=====================================
tests/test_difference.py
=====================================
@@ -63,40 +63,42 @@ def test_too_long_diff_block_lines(monkeypatch):
def test_size_updates():
- d = Difference("0123456789", "path1", "path2")
+ d = Difference("path1", "path2", unified_diff="0123456789")
assert_size(d, 20)
- d.add_details([Difference("0123456789", "path1/a", "path2/a")])
+ d.add_details(
+ [Difference("path1/a", "path2/a", unified_diff="0123456789")]
+ )
assert_size(d, 44)
d.add_comment("lol1")
assert_size(d, 48)
def test_traverse_heapq():
- d0 = Difference("0", "path1/a", "path2/a")
- d1 = Difference("012", "path1/b", "path2/b")
- d2 = Difference("01", "path1/c", "path2/c")
+ d0 = Difference("path1/a", "path2/a", unified_diff="0")
+ d1 = Difference("path1/b", "path2/b", unified_diff="012")
+ d2 = Difference("path1/c", "path2/c", unified_diff="01")
d0.add_details(
[
- Difference("012345678", "path1/a/1", "path2/a/1"),
- Difference("0123", "path1/a/2", "path2/a/2"),
- Difference("012", "path1/a/3", "path2/a/3"),
+ Difference("path1/a/1", "path2/a/1", unified_diff="012345678"),
+ Difference("path1/a/2", "path2/a/2", unified_diff="0123"),
+ Difference("path1/a/3", "path2/a/3", unified_diff="012"),
]
)
d1.add_details(
[
- Difference("01234567", "path1/b/1", "path2/b/1"),
- Difference("01234", "path1/b/2", "path2/b/2"),
- Difference("012345", "path1/b/3", "path2/b/3"),
+ Difference("path1/b/1", "path2/b/1", unified_diff="01234567"),
+ Difference("path1/b/2", "path2/b/2", unified_diff="01234"),
+ Difference("path1/b/3", "path2/b/3", unified_diff="012345"),
]
)
d2.add_details(
[
- Difference("01", "path1/c/1", "path2/c/1"),
- Difference("0123456789", "path1/c/2", "path2/c/2"),
- Difference("0123456", "path1/c/3", "path2/c/3"),
+ Difference("path1/c/1", "path2/c/1", unified_diff="01"),
+ Difference("path1/c/2", "path2/c/2", unified_diff="0123456789"),
+ Difference("path1/c/3", "path2/c/3", unified_diff="0123456"),
]
)
- diff = Difference("0123456789", "path1", "path2")
+ diff = Difference("path1", "path2", unified_diff="0123456789")
diff.add_details([d0, d1, d2])
# traverse nodes in depth order, but at a given depth traverse the nodes
# there from smallest diff (counted non-recursively) to largest
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/a3bfba06da482fa1e9ee1a8733aa0f54d29c8e32
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/a3bfba06da482fa1e9ee1a8733aa0f54d29c8e32
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20210409/5ab429b5/attachment.htm>
More information about the rb-commits
mailing list