| 1 |
#!/bin/rc |
| 2 |
# 9diff - Mercurial extdiff wrapper for diff(1) |
| 3 |
|
| 4 |
rfork e |
| 5 |
|
| 6 |
fn getfiles { |
| 7 |
cd $1 && |
| 8 |
for(f in `{du -as | awk '{print $2}'}) |
| 9 |
test -f $f && echo `{cleanname $f} |
| 10 |
} |
| 11 |
|
| 12 |
fn usage { |
| 13 |
echo >[1=2] usage: 9diff [diff options] parent child root |
| 14 |
exit usage |
| 15 |
} |
| 16 |
|
| 17 |
opts=() |
| 18 |
while(~ $1 -*){ |
| 19 |
opts=($opts $1) |
| 20 |
shift |
| 21 |
} |
| 22 |
if(! ~ $#* 3) |
| 23 |
usage |
| 24 |
|
| 25 |
# extdiff will set the parent and child to a single file if there is |
| 26 |
# only one change. If there are multiple changes, directories will be |
| 27 |
# set. diff(1) does not cope particularly with directories; instead we |
| 28 |
# do the recursion ourselves and diff each file individually. |
| 29 |
if(test -f $1) |
| 30 |
diff $opts $1 $2 |
| 31 |
if not{ |
| 32 |
# extdiff will create a snapshot of the working copy to prevent |
| 33 |
# conflicts during the diff. We circumvent this behavior by |
| 34 |
# diffing against the repository root to produce plumbable |
| 35 |
# output. This is antisocial. |
| 36 |
for(f in `{sort -u <{getfiles $1} <{getfiles $2}}){ |
| 37 |
file1=$1/$f; test -f $file1 || file1=/dev/null |
| 38 |
file2=$3/$f; test -f $file2 || file2=/dev/null |
| 39 |
diff $opts $file1 $file2 |
| 40 |
} |
| 41 |
} |
| 42 |
exit '' |