This morning I reviewed and pushed the patch for Koha bug 11174. The patch, by Zeno Tajoli, removes one character each from two files.
One character? That should be easy to eyeball, right?
Not quite — the character in question was part of a parameter name in a very long URL. I don’t know about you, but it can take me a while to spot such a difference.
Here is an example. Can you spot the exact difference in less than 2 seconds?
$ git diff --color diff --git a/INSTALL b/INSTALL index ffe69ae..e92b1a3 100644 --- a/INSTALL +++ b/INSTALL @@ -94,7 +94,7 @@ Use the packaged version or install from CPAN sudo make upgrade Koha 3.4.x or later no longer stores items in biblio records. -If you are upgrading from an older version ou will need to do the +If you are upgrading from an older version you will need to do the following two steps, they can take a long time (several hours) to complete for large databases
Now imagine doing this if the change occurs in the 100th character of a line that is 150 characters long.
Fortunately, git diff
, as well as other commands like git show
that display diffs, accepts several switches that let you display the differences in terms of words, not lines. These switches include --word-diff
and --color-words
. For example:
$ git diff --color-words diff --git a/INSTALL b/INSTALL index ffe69ae..e92b1a3 100644 --- a/INSTALL +++ b/INSTALL @@ -94,7 +94,7 @@ Use the packaged version or install from CPAN sudo make upgrade Koha 3.4.x or later no longer stores items in biblio records. If you are upgrading from an older version ouyou will need to do the following two steps, they can take a long time (several hours) to complete for large databases
The difference is much easier to see now — at least if you’re not red-green color-blind. You can change the colors or not use colors at all:
$ git diff --word-diff diff --git a/INSTALL b/INSTALL index ffe69ae..e92b1a3 100644 --- a/INSTALL +++ b/INSTALL @@ -94,7 +94,7 @@ Use the packaged version or install from CPAN sudo make upgrade Koha 3.4.x or later no longer stores items in biblio records. If you are upgrading from an older version [-ou-]{+you+} will need to do the following two steps, they can take a long time (several hours) to complete for large databases
Going back to the bug I mentioned, --word-diff
wasn’t quite enough, though. By default, Git considers words to be delimited by whitespace, but the patch in question removed a character from the middle of a very long URL. To make the change pop out, I had to tell Git to highlight single-character changes. One way to do this is the --word-diff-regex
or by passing the regex to --color-words.
Here’s the final example:
$ git diff --color-words=. diff --git a/INSTALL b/INSTALL index ffe69ae..e92b1a3 100644 --- a/INSTALL +++ b/INSTALL @@ -94,7 +94,7 @@ Use the packaged version or install from CPAN sudo make upgrade Koha 3.4.x or later no longer stores items in biblio records. If you are upgrading from an older version you will need to do the following two steps, they can take a long time (several hours) to complete for large databases
And there we have it — the difference, pinpointed.