From 6adf151d838d943b1de06c7c9ffc492117d8e362 Mon Sep 17 00:00:00 2001 From: Sighery Date: Sun, 19 Jan 2020 19:09:03 +0100 Subject: [PATCH 1/2] Fix diff order to compare dst with src The current diffs are confusing, since they compare the source against the destination file. To make it less confusing: source is the file that contains modifications, and destination is the one to be overwritten. With the current order, it displays changes as if you were applying the destination file on the source file. This commit makes it so that it displays the changes it would need to apply source on destination. This is consistent with tools such as patch, that take first the destination file, and second the patch you're going to apply. Diffing should be done the same way, first the destination, second the file with the new changes. This is how other tools that provide diffs such as git also work. --- dotdrop/installer.py | 2 +- dotdrop/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dotdrop/installer.py b/dotdrop/installer.py index a08cbc1..d3addad 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -444,7 +444,7 @@ class Installer: # fake the output for readability if not diff: return - self.log.log('diff \"{}\" VS \"{}\"'.format(src, dst)) + self.log.log('diff \"{}\" VS \"{}\"'.format(dst, src)) self.log.emph(diff) def _create_dirs(self, directory): diff --git a/dotdrop/utils.py b/dotdrop/utils.py index c4b82e2..3da940e 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -72,7 +72,7 @@ def shell(cmd, debug=False): def diff(src, dst, raw=True, opts='', debug=False): """call unix diff to compare two files""" - cmd = 'diff -r {} \"{}\" \"{}\"'.format(opts, src, dst) + cmd = 'diff -r {} \"{}\" \"{}\"'.format(opts, dst, src) _, out = run(shlex.split(cmd), raw=raw, debug=debug) return out From 0658df361d8b72804c917b3f4a01662b065f4644 Mon Sep 17 00:00:00 2001 From: Sighery Date: Tue, 21 Jan 2020 20:54:24 +0100 Subject: [PATCH 2/2] Rename diff arguments for better clarity --- dotdrop/comparator.py | 2 +- dotdrop/installer.py | 2 +- dotdrop/utils.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dotdrop/comparator.py b/dotdrop/comparator.py index bb874c4..7cab104 100644 --- a/dotdrop/comparator.py +++ b/dotdrop/comparator.py @@ -123,7 +123,7 @@ class Comparator: def _diff(self, left, right, header=False): """diff using the unix tool diff""" - out = diff(left, right, raw=False, + out = diff(modified=left, original=right, raw=False, opts=self.diffopts, debug=self.debug) if header: lshort = os.path.basename(left) diff --git a/dotdrop/installer.py b/dotdrop/installer.py index d3addad..2c5936a 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -437,7 +437,7 @@ class Installer: if content: tmp = utils.write_to_tmpfile(content) src = tmp - diff = utils.diff(src, dst, raw=False) + diff = utils.diff(modified=src, original=dst, raw=False) if tmp: utils.remove(tmp, quiet=True) diff --git a/dotdrop/utils.py b/dotdrop/utils.py index 3da940e..893af71 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -70,9 +70,9 @@ def shell(cmd, debug=False): return ret == 0, out -def diff(src, dst, raw=True, opts='', debug=False): +def diff(original, modified, raw=True, opts='', debug=False): """call unix diff to compare two files""" - cmd = 'diff -r {} \"{}\" \"{}\"'.format(opts, dst, src) + cmd = 'diff -r {} \"{}\" \"{}\"'.format(opts, original, modified) _, out = run(shlex.split(cmd), raw=raw, debug=debug) return out