mookid / diffr

Yet another diff highlighting tool
MIT License
572 stars 22 forks source link

highlights unchanged parts. #15

Closed ghuls closed 5 years ago

ghuls commented 5 years ago

diffr seems to highlight unchanged parts. At least when there are a different number of leading spaces and dashes following those spaces.

$ diff -u <(printf '    -01234;\n    --abc;\n    --def;\n') <(printf '      -01234;\n      --abc;\n      --def;\n') | diffr
--- /dev/fd/63  2019-07-22 10:03:08.009841265 +0200
+++ /dev/fd/62  2019-07-22 10:03:08.013841298 +0200
@@ -1,3 +1,3 @@
-    -01234;
-    --abc;
-    --def;
+      -01234;
+      --abc;
+      --def;

The second dash in --def is colored in read, which shouldn't be the case.

$ diff -u <(printf '    -01234;\n    --abc;\n    --def;\n    --jkl;\n    --poi;\n') <(printf '      -01234;\n      --abc;\n      --def;\n      --jkl;\n      --poi;\n') | diffr
--- /dev/fd/63  2019-07-22 10:10:29.065613277 +0200
+++ /dev/fd/62  2019-07-22 10:10:29.065613277 +0200
@@ -1,5 +1,5 @@
-    -01234;
-    --abc;
-    --def;
-    --jkl;
-    --poi;
+      -01234;
+      --abc;
+      --def;
+      --jkl;
+      --poi;

In this case the following dashes are highligthed:

In both cases it should only highlight the leading spaces as that is the only part that changed.

With underscores the highlighting works fine:

$ diff -u <(printf '    _01234;\n    __abc;\n    __def;\n    __jkl;\n    __poi;\n') <(printf '      _01234;\n      __abc;\n      __def;\n      __jkl;\n      __poi;\n') | diffr
--- /dev/fd/63  2019-07-22 10:25:01.873156289 +0200
+++ /dev/fd/62  2019-07-22 10:25:01.877156323 +0200
@@ -1,5 +1,5 @@
-    _01234;
-    __abc;
-    __def;
-    __jkl;
-    __poi;
+      _01234;
+      __abc;
+      __def;
+      __jkl;
+      __poi;
mookid commented 5 years ago

Thanks for the detailed report! I'll investigate further.

mookid commented 5 years ago

Thanks @ghuls !

For the record: the LCS computed was correct (the concatenation of all the non-highlighted parts on added and removed are identical). The issue was that the LCS was computed on a stream of token containing the line markers.

ghuls commented 5 years ago

Another issue now with the following diff.

The --include and --include lines are highlighted completely (worked before).

diff --git a/ngs_runs_backup.sh b/ngs_runs_backup.sh
index 2479c97..9673455 100755
--- a/ngs_runs_backup.sh
+++ b/ngs_runs_backup.sh
@@ -13,25 +13,27 @@ NGS_RUNS_ARCHIVE_DIR='/ngs_runs/'

 ngs_runs_backup_dry_run () {
-    rsync --dry-run \
-         -rlptDv \
-        --include '+ */'\
+    rsync \
+        --dry-run \
+        -rlptDv \
+        --include '+ */' \
         --include '+ *q.gz' \
         --exclude '- *' \
         --prune-empty-dirs \
         "${NGS_RUNS_STAGING_DIR}" \
-        "${NGS_RUNS_ARCHIVE_DIR}"
+        "${NGS_RUNS_ARCHIVE_DIR}";
 }

 ngs_runs_backup_for_real () {
-    rsync --progress \
+    rsync \
+        --progress \
         -rlptDv \
-        --include '+ */'\
+        --include '+ */' \
         --include '+ *q.gz' \
         --exclude '- *' \
         --prune-empty-dirs \
         "${NGS_RUNS_STAGING_DIR}" \
-        "${NGS_RUNS_ARCHIVE_DIR}"
+        "${NGS_RUNS_ARCHIVE_DIR}";
 }