From 1d047a09752957a772ea0abec098e1af96e9a78d Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Wed, 10 Nov 2004 13:24:50 +0000 Subject: [PATCH] Alejandro Mery: * compare.sh updated (no pkgfork support) [2004110416400416194] (https://www.rocklinux.net/submaster) git-svn-id: http://www.rocklinux.org/svn/rock-linux/trunk@4781 c5f82cb5-29bc-0310-9cd0-bff59a50e3bc --- misc/archive/compare.sh | 134 +++++++++++++++++++++++++++++++++------- 1 file changed, 112 insertions(+), 22 deletions(-) diff --git a/misc/archive/compare.sh b/misc/archive/compare.sh index 7e4bf70bc..163389639 100644 --- a/misc/archive/compare.sh +++ b/misc/archive/compare.sh @@ -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] [-repository ||]" - echo "usage: $0 [-q] -3 [-repository ||]" + echo "usage: $0 [-q[q]] [-v] [-r] {action}" + echo + echo "action: [-p [-P] [-S]] [-repository ||]" + echo " -3 [-repository ||]" + 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 " 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