Mdiff: Difference between revisions
No edit summary |
No edit summary |
||
Line 15: | Line 15: | ||
== Installing mdiff.sh == | == Installing mdiff.sh == | ||
You also need the shell script '''mdiff.sh''' which should be placed in your '''$HOME/bin'''. You also need to make the script executable, use the command: '''chmod 755 mdiff.sh'''. You may need to edit line | You also need the shell script '''mdiff.sh''' which should be placed in your '''$HOME/bin'''. You also need to make the script executable, use the command: '''chmod 755 mdiff.sh'''. You may need to edit line 6 (GUIDIFF=) to reflect which graphical diff program you have installed. The code for mdiff.sh follows: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> |
Revision as of 10:25, 26 May 2011
Source code comparison
The scenario of wanting to know what has changed between two versions of source code often arises. For example, you are running a specific version of a model (SPINS, MITgcm, IGW, etc.) while the model is being improved by the developers. After a few weeks or months pass, a lot of differences accumulate between the latest greatest version and the version you are actually running. It's not always easy to determine what has changed, particularly if a revision control system is not being used.
Command line diff can be helpful, but, reading the output of diff is awkward and the context is usually omitted. ("Sure, line 75 has been replaced, but what subroutine is that in?"). The script mdiff.sh is designed to alleviate this problem.
Installing a graphical diff program
You will need a graphical diff program (xdiff, xxdiff, fldiff, etc) and fldiff is recommended. For ubuntu linux, this may be installed by the command
$ sudo apt-get install fldiff
If you don't have ubuntu, check your package manager for the fldiff package. Failing that, install it from source code from http://www.easysw.com/~mike/fldiff/index.html.
Installing mdiff.sh
You also need the shell script mdiff.sh which should be placed in your $HOME/bin. You also need to make the script executable, use the command: chmod 755 mdiff.sh. You may need to edit line 6 (GUIDIFF=) to reflect which graphical diff program you have installed. The code for mdiff.sh follows:
#!/bin/bash
# A directory compare script for comparing source codes
# Usage: mdiff.sh dir1 dir2
DIFF=diff
GUIDIFF=fldiff
if [ $# -lt 2 ]; then
echo "quit!"
exit 1;
fi
OI="Only in"
if [ -d $1 ] && [ -d $2 ]; then
$DIFF -r -b --brief --exclude=.svn \
$1 $2 \
| sed s/"Files"/$GUIDIFF/g | sed s/" and "/" "/g \
| sed s/differ//g | grep -v "$OI"
fi
Usage
Now that you have both fldiff and mdiff.sh you can compare directories by
$ mdiff.sh dir1 dir2
You will be presented with a graphical window that shows a file from dir1 on the left and from dir2 on the right, with differences highlighted. Press Ctrl+Q to close that window and proceed to the next file. The result is that with one command, you can rapidly scroll through all files that have changed and see the differences.
This script is useful for source code, LaTeX code, MATLAB code, or anything else that lives in a large number of flat text files.
A screenshot of fldiff is shown on the author's website: http://www.easysw.com/~mike/fldiff/index.html#screenshot