Mdiff: Difference between revisions
No edit summary |
mNo 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 | You also need the shell script '''mdiff.sh''' which should be placed in your '''$HOME/bin'''. You may need to edit line 9 (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 13:30, 19 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 may need to edit line 9 (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 [S]
# where specifying S will cause the script to show the "only in" entries
#
# Michael Dunphy 23 Nov 2005
DIFF=diff
GUIDIFF=fldiff
if [ $# -lt 2 ]; then
echo "quit!"
exit 1;
fi
if [ -z $3 ]; then
OI="Only in"
else
OI="NOT_REMOVING_ONLY_IN_ENTRIES"
fi
d1=$1
d2=$2
if [ -d $d1 ] && [ -d $d2 ]; then
# $HOME/bin/gdiff -r -b --brief \
$DIFF -r -b --exclude=.svn --brief \
$d1 $d2 \
| 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 dir1 dir2 | sh
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.