about summary refs log tree commit diff
path: root/patch/bdiff.sh
blob: 1515319738d37bb9dd4bc416eef66d1f0386a583 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /bin/sh -e

#DIFF=/home/eelco/Dev/nix/zdelta-2.1/zdc
DIFF=/home/eelco/Dev/nix/bsdiff-4.2/bsdiff

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

	echo "FILE DELTA FOR $fn"

        TMPFILE=/tmp/__bsdiff
	$DIFF "$srcA/$fn" "$srcB/$fn" $TMPFILE
        cat $TMPFILE

        diffSize=$(stat -c '%s' $TMPFILE)

        # For comparison.
        bzipSize=$(bzip2 < "$srcB/$fn" | wc -m)

        gain=$(echo "scale=2; ($diffSize - $bzipSize) / $bzipSize * 100" | bc)

        ouch=$(if test "${gain:0:1}" != "-"; then echo "!"; fi)

        printf "%7.2f %1s %10d %10d %s\n" \
            "$gain" "$ouch" "$diffSize" "$bzipSize" "$fn" >&2
#        echo "$fn -> $diffSize $bzipSize ==> $gain  $ouch" >&2

        rm $TMPFILE

    else

	echo "NEW FILE $fn"

	cat "$srcB/$fn"

    fi

done