|
|
@ -1,16 +1,32 @@ |
|
|
|
#!/bin/sh |
|
|
|
exec 2>&1 |
|
|
|
|
|
|
|
verbose=0 |
|
|
|
quiet=0 |
|
|
|
|
|
|
|
ignspace=0 |
|
|
|
ignprio=0 |
|
|
|
ignrepo=0 |
|
|
|
dopatch=0 |
|
|
|
|
|
|
|
source= |
|
|
|
targets= |
|
|
|
repositories= |
|
|
|
packages= |
|
|
|
|
|
|
|
function show_usage() { |
|
|
|
echo "usage: $0 [-q] [-v] <source> <target> [-repository <repo>|<packages>|]" |
|
|
|
echo "usage: $0 [-q] -3 <source> <target1> <target2> [-repository <repo>|<packages>|]" |
|
|
|
echo "usage: $0 [-q[q]] [-v] [-r] {action}" |
|
|
|
echo |
|
|
|
echo "action: [-p [-P] [-S]] <source> <target> [-repository <repo>|<packages>|]" |
|
|
|
echo " -3 <source> <target1> <target2> [-repository <repo>|<packages>|]" |
|
|
|
echo |
|
|
|
echo " -q: don't show packages with the same version" |
|
|
|
echo " -qq: don't show packages missing or with the same version" |
|
|
|
echo " -v: show extra info about the packages" |
|
|
|
echo " -r: don't show repository name" |
|
|
|
echo |
|
|
|
echo " -p: show patch to turn \$source into \$target" |
|
|
|
echo " -P: ignore [P]s of .desc files on patches" |
|
|
|
echo " -S: ignore spaces on patches" |
|
|
|
} |
|
|
|
|
|
|
|
# TODO: it would be great to port it to "-n <n>" instead of -3 |
|
|
@ -18,10 +34,17 @@ function show_usage() { |
|
|
|
while [ $# -gt 0 ]; do |
|
|
|
case "$1" in |
|
|
|
-v) verbose=1 ;; |
|
|
|
-r) ignrepo=1 ;; |
|
|
|
-q) quiet=1 ;; |
|
|
|
-qq) quiet=2 ;; |
|
|
|
-p) dopatch=1 ;; |
|
|
|
-P) ignprio=1 ;; |
|
|
|
-S) ignspace=1 ;; |
|
|
|
|
|
|
|
-3) source="$2" |
|
|
|
targets="$3 $4" |
|
|
|
shift 3 ;; |
|
|
|
|
|
|
|
-repository) |
|
|
|
shift |
|
|
|
repositories="$*"; set -- |
|
|
@ -37,29 +60,68 @@ while [ $# -gt 0 ]; do |
|
|
|
shift |
|
|
|
done |
|
|
|
|
|
|
|
#if [ $verbose -eq 1 ]; then |
|
|
|
# echo " verbosity: $verbose" |
|
|
|
# echo " source: $source" |
|
|
|
# echo " targets: $targets" |
|
|
|
# echo "repositories: $repositories" |
|
|
|
# echo " packages: $packages" |
|
|
|
#fi 1>&2 |
|
|
|
function remove_header() { |
|
|
|
# thanks you blindcoder :) |
|
|
|
# |
|
|
|
local here=0 count=1 |
|
|
|
while read line ; do |
|
|
|
count=$(( ${count} + 1 )) |
|
|
|
[ "${line//COPYRIGHT-NOTE-END/}" != "${line}" ] && here=${count} |
|
|
|
done < $1 |
|
|
|
tail -n +${here} $1 |
|
|
|
} |
|
|
|
function show_nice_diff() { |
|
|
|
local diffopt= |
|
|
|
[ $ignspace -eq 1 ] && diffopt='-EBb' |
|
|
|
|
|
|
|
diff -u $diffopt "$1" "$2" | sed \ |
|
|
|
-e 's,^--- .*,--- old/package/'"${3##*/package/}," \ |
|
|
|
-e 's,^[\+][\+][\+] .*,+++ new/package/'"${3##*/package/}," |
|
|
|
} |
|
|
|
|
|
|
|
function diff_package() { |
|
|
|
local source="$1" |
|
|
|
local target="$1" |
|
|
|
local target="$2" |
|
|
|
local x= y= |
|
|
|
|
|
|
|
# files on source |
|
|
|
for x in $source/*; do |
|
|
|
if [ -d "$x" ]; then |
|
|
|
if [ -d "$x/" ]; then |
|
|
|
diff_package $x $target/${x##*/} |
|
|
|
elif [ -f $x -a -f $target/${x##*/} ]; then |
|
|
|
echo diff -u $x $target/${x##*/} |
|
|
|
elif [[ "$x" = *.cache ]]; then |
|
|
|
continue |
|
|
|
else |
|
|
|
echo diff -u $x /dev/null |
|
|
|
remove_header $x > $$.source |
|
|
|
if [ -f $target/${x##*/} ]; then |
|
|
|
remove_header $target/${x##*/} > $$.target |
|
|
|
|
|
|
|
if [[ "$x" = *.desc ]]; then |
|
|
|
y=$( grep -e "^\[P\]" $x ) |
|
|
|
[ "$y" -a $ignprio -eq 1 ] && sed -i -e "s,^\[P\] .*,$y," $$.target |
|
|
|
fi |
|
|
|
|
|
|
|
show_nice_diff $$.source $$.target $x |
|
|
|
rm $$.target |
|
|
|
else |
|
|
|
show_nice_diff $$.source /dev/null $x |
|
|
|
fi |
|
|
|
rm $$.source |
|
|
|
fi |
|
|
|
done |
|
|
|
# files only on target |
|
|
|
for x in $target/*; do |
|
|
|
if [ -d $x/ ]; then |
|
|
|
[ ! -d $source/${x#$target/} ] && diff_package $source/${x#$target/} $x |
|
|
|
elif [[ "$x" = *.cache ]]; then |
|
|
|
continue |
|
|
|
else |
|
|
|
if [ ! -f $source/${x#$target/} ]; then |
|
|
|
remove_header $x > $$.target |
|
|
|
show_nice_diff /dev/null $$.target $source/${x#$target/} |
|
|
|
rm $$.target |
|
|
|
fi |
|
|
|
fi |
|
|
|
done |
|
|
|
# TODO: files only on target |
|
|
|
} |
|
|
|
|
|
|
|
# grabdata confdir field |
|
|
@ -103,11 +165,19 @@ function grabdata_cache() { |
|
|
|
echo "$output" |
|
|
|
} |
|
|
|
function compare_package() { |
|
|
|
local pkg=${1##*/} |
|
|
|
local source=$1 |
|
|
|
local fullpkg=${1##*/package/} |
|
|
|
local pkg=${1##*/} |
|
|
|
local target= x= missing=0 |
|
|
|
|
|
|
|
local info= |
|
|
|
local srcver= srcstatus= srcsize= |
|
|
|
local tgtver= tgtstatus= tgtsize= |
|
|
|
|
|
|
|
shift; |
|
|
|
|
|
|
|
[ $ignrepo -eq 1 ] && fullpkg=$pkg |
|
|
|
|
|
|
|
srcver=$( grabdata $source $pkg version ) |
|
|
|
srcstatus=$( grabdata $source $pkg status ) |
|
|
|
srcsize=$( grabdata $source $pkg size ) |
|
|
@ -133,6 +203,8 @@ function compare_package() { |
|
|
|
tgtstatus="${tgtstatus#:}" |
|
|
|
tgtsize="${tgtsize#:}" |
|
|
|
|
|
|
|
# do we have different versions? |
|
|
|
# |
|
|
|
equalver=1 equalstatus=1 |
|
|
|
IFS=':' ; for x in $tgtver; do |
|
|
|
[ "$x" != "$srcver" ] && equalver=0 |
|
|
@ -141,6 +213,8 @@ function compare_package() { |
|
|
|
[ "$x" != "$srcstatus" ] && equalstatus=0 |
|
|
|
done |
|
|
|
|
|
|
|
# optimize version and status if they are the same |
|
|
|
# |
|
|
|
if [ $equalver -eq 1 ]; then |
|
|
|
version=$srcver |
|
|
|
else |
|
|
@ -153,13 +227,30 @@ function compare_package() { |
|
|
|
status="$srcstatus -> $tgtstatus" |
|
|
|
fi |
|
|
|
|
|
|
|
# acording to verbosity level, what info should i show? |
|
|
|
# |
|
|
|
if [ $verbose -eq 0 ]; then |
|
|
|
info="($version)" |
|
|
|
else |
|
|
|
info="($version) ($status) ($srcsize -> $tgtsize)" |
|
|
|
fi |
|
|
|
|
|
|
|
if [ $missing -eq 1 ]; then |
|
|
|
echo "- $pkg ($version) ($status) ($srcsize -> $tgtsize)" 1>&2 |
|
|
|
if [ $quiet -le 1 ]; then |
|
|
|
# New - the package is not available at target tree |
|
|
|
echo "N $fullpkg $info" 1>&2 |
|
|
|
[ $dopatch -eq 1 ] && diff_package $source $target |
|
|
|
fi |
|
|
|
elif [ $equalver -eq 1 ]; then |
|
|
|
[ $quiet -eq 0 ] && echo "* $pkg ($version) ($status) ($srcsize -> $tgtsize)" 1>&2 |
|
|
|
if [ $quiet -eq 0 ]; then |
|
|
|
# Equal - the versions and cache status are the same on both trees |
|
|
|
echo "E $fullpkg $info" 1>&2 |
|
|
|
[ $dopatch -eq 1 ] && diff_package $source $target |
|
|
|
fi |
|
|
|
else |
|
|
|
echo "+ $pkg ($version) ($status) ($srcsize:$tgtsize)" 1>&2 |
|
|
|
[ "$verbose" -eq 1 ] && diff_package $source $target |
|
|
|
# Modified - the version on both trees is different |
|
|
|
echo "M $fullpkg $info" 1>&2 |
|
|
|
[ $dopatch -eq 1 ] && diff_package $source $target |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
@ -188,7 +279,6 @@ if [ $allexist -eq 1 ]; then |
|
|
|
done |
|
|
|
else |
|
|
|
for repo in $source/package/*; do |
|
|
|
echo "repository: ${repo##*/}" 1>&2 |
|
|
|
for x in $repo/*; do |
|
|
|
[ -d "$x" ] && compare_package $x $targets |
|
|
|
done |
|
|
|