The CRM that my company uses is SugarCRM. We use the professional version as we wanted quoting, but there is an open source version available. We have also elected to have the on-site option, meaning we host it ourselves. There is an on-demand option that gets the task of running a server out of your hands and puts it in Sugar’s hands.
We have extensively modified our install of SugarCRM, which is written largely in php, with a little javascript thrown in. This means whenever Sugar updates their code, we start a laborious process of making sure our existing customization doesn’t get borked during the update.
The first few times this happened, we went through each file we had updated line by line. We had noted what files had been modified, but we still had review each updated file with a fine-tooth comb to make sure nothing broke. Invariably something broke. We have been able to fix everything, but not without at least a small impact on our sales staff.
I realized that some tool must have been written for developers and kernel updaters to compare files. My search quickly ended when I found the old *nix standby diff. I still have not mastered diff, but I know enough now so the update time has dropped drastically, and the errors that occur at an update have also been greatly cut.
Diff has many options and ways you can see the changes, from ignoring white space differences, to only showing what has changed, to side-by-side views. Here are a few that I have found extremely helpful.
First, this is how you use diff.
$ diff <options> <file1> <file2>
You can run diff without any options, but I don’t find it particularly useful.
Having an side-by-side option is great, though it has its limitations. I first started getting better with diff when, by trial and error, I figured out what worked for me. Sugar files have some very long lines, so I made my terminal as wide as the screen. I then ran the following command.
$ diff -y -W 120 <file1> <file2>
The “-y” flag puts each file side-by-side. The second flag (-W) tells diff not to use the default width and the number following the flag is the width you want. So in this case I set it for 120 characters. This shows you the entire file, however, the point of diff often is to find the difference, hence the name. We can take diff a step further to really narrow down our focus by adding the –suppress-common-lines flag.
$diff -y -W 120 –suppress-common-lines <file1> <file2>
Now you have all the lines diff has marked as different. In the column between the two files diff helps you find the differences. There are three common markers that are displayed here. They are >, < and | (that’s a pipe). If you see > in the middle column, the file on the right–which is <file2> has a line that the first file does not have. The arrow pointing like < means the opposite. If you see a pipe in the middle “|”, then each file has the line, but the line is different in each file. Here is a brief example of what that may look like:
if(!empty($_REQU | if(!empty($_
if (file_exists( <
$sugar_smart <
$sugar_smart <
} <
else { <
$sugar_smart | $sugar_smarty->a
} <
You can see most of the lines in this example are in the first file. There are two lines that have code, but something is different in them.
There are many other ways to use diff. Not all are side-by-side options. Many prefer just having the number of the lines that are changed. I, so far, prefer side-by-side. I find my tastes and ways of doing things are constantly changing as my experience level grows, so what may be easy for me today, is slow and cumbersome a month from now.
Have fun and keep exploring what hidden tools your Linux install has for you.