2004-11-29 20:12:55 +01:00
|
|
|
#! /bin/sh -e
|
|
|
|
|
2004-12-16 15:59:05 +01:00
|
|
|
#DIFF=zdc
|
|
|
|
DIFF=bsdiff
|
2004-11-29 20:12:55 +01:00
|
|
|
|
|
|
|
srcA=$1
|
|
|
|
srcB=$2
|
|
|
|
|
|
|
|
if test -z "$srcA" -o -z "$srcB"; then
|
|
|
|
echo "syntax: bdiff.sh srcA srcB"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
(cd $srcB && find . -type f) | while read fn; do
|
|
|
|
|
|
|
|
if test -f "$srcA/$fn"; then
|
|
|
|
|
2004-12-16 15:59:05 +01:00
|
|
|
if ! test -f "$srcB/$fn"; then
|
|
|
|
echo "DELETE $fn"
|
|
|
|
else
|
2004-11-29 20:12:55 +01:00
|
|
|
|
2004-12-16 15:59:05 +01:00
|
|
|
if ! cmp "$srcA/$fn" "$srcB/$fn" > /dev/null; then
|
|
|
|
|
|
|
|
echo "FILE DELTA FOR $fn"
|
2004-11-29 22:04:28 +01:00
|
|
|
|
2004-12-16 15:59:05 +01:00
|
|
|
TMPFILE=/tmp/__bsdiff
|
|
|
|
$DIFF "$srcA/$fn" "$srcB/$fn" $TMPFILE
|
|
|
|
cat $TMPFILE
|
2004-11-29 22:04:28 +01:00
|
|
|
|
2004-12-16 15:59:05 +01:00
|
|
|
diffSize=$(stat -c '%s' $TMPFILE)
|
2004-11-29 22:04:28 +01:00
|
|
|
|
2004-12-16 15:59:05 +01:00
|
|
|
# For comparison.
|
|
|
|
bzipSize=$(bzip2 < "$srcB/$fn" | wc -m)
|
2004-11-29 22:04:28 +01:00
|
|
|
|
2004-12-16 15:59:05 +01:00
|
|
|
gain=$(echo "scale=2; ($diffSize - $bzipSize) / $bzipSize * 100" | bc)
|
2004-11-29 22:04:28 +01:00
|
|
|
|
2004-12-16 15:59:05 +01:00
|
|
|
ouch=$(if test "${gain:0:1}" != "-"; then echo "!"; fi)
|
|
|
|
|
|
|
|
printf "%7.2f %1s %10d %10d %s\n" \
|
|
|
|
"$gain" "$ouch" "$diffSize" "$bzipSize" "$fn" >&2
|
2004-11-29 22:04:28 +01:00
|
|
|
# echo "$fn -> $diffSize $bzipSize ==> $gain $ouch" >&2
|
|
|
|
|
2004-12-16 15:59:05 +01:00
|
|
|
rm $TMPFILE
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Note: be silent about unchanged files.
|
2004-11-29 20:12:55 +01:00
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
echo "NEW FILE $fn"
|
|
|
|
|
|
|
|
cat "$srcB/$fn"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|