2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # T2 SDE: misc/archive/compare.sh
6 # Copyright (C) 2004 - 2005 The T2 SDE Project
8 # More information can be found in the files COPYING and README.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
29 function show_usage
() {
30 echo "usage: $0 [-q[q]] [-v] [-r] {action}"
32 echo "action: [-p [-P] [-S]] <source> <target> [-repository <repo>|<packages>|]"
33 echo " -3 <source> <target1> <target2> [-repository <repo>|<packages>|]"
35 echo " -q: don't show packages with the same version"
36 echo " -qq: don't show packages missing or with the same version"
37 echo " -v: show extra info about the packages"
38 echo " -r: don't show repository name"
40 echo " -p: show patch to turn \$source into \$target"
41 echo " -P: ignore [P]s of .desc files on patches"
42 echo " -S: ignore spaces on patches"
45 # TODO: it would be great to port it to "-n <n>" instead of -3
47 while [ $# -gt 0 ]; do
63 repositories
="$*"; set --
65 *) if [ "$targets" ]; then
67 elif [ "$source" ]; then
76 function remove_header
() {
77 # thanks you blindcoder :)
81 count
=$
(( ${count} + 1 ))
82 [ "${line//COPYRIGHT-NOTE-END/}" != "${line}" ] && here=${count}
86 function show_nice_diff() {
88 [ $ignspace -eq 1 ] && diffopt='-EBb'
90 diff -u $diffopt "$1" "$2" | sed \
91 -e 's,^--- .*,--- old/package/'"${3##*/package/}," \
92 -e 's,^[\+][\+][\+] .*,+++ new/package/'"${3##*/package/},"
95 function diff_package() {
101 for x in $source/*; do
102 if [ -d "$x/" ]; then
103 diff_package $x $target/${x##*/}
104 elif [[ "$x" = *.cache ]]; then
106 elif [ -f "$x" ]; then
107 remove_header $x > $$.source
108 if [ -f $target/${x##*/} ]; then
109 remove_header $target/${x##*/} > $$.target
111 if [[ "$x" = *.desc ]]; then
112 y=$( grep -e "^\
[P\
]" $x )
113 [ "$y" -a $ignprio -eq 1 ] && sed -i -e "s
,^\
[P\
] .
*,$y," $$.target
116 show_nice_diff $$.source $$.target $x
119 show_nice_diff $$.source /dev/null $x
124 # files only on target
125 for x in $target/*; do
127 [ ! -d $source/${x#$target/} ] && diff_package $source/${x#$target/} $x
128 elif [[ "$x" = *.cache ]]; then
130 elif [ -f "$x" ]; then
131 if [ ! -f "$source/${x#$target/}" ]; then
132 remove_header $x > $$.target
133 show_nice_diff /dev/null $$.target $source/${x#$target/}
140 # grabdata confdir field
141 function grabdata() {
148 version) output=$( grabdata_desc $confdir/$pkg.desc $field ) ;;
149 *) output=$( grabdata_cache $confdir/$pkg.cache $field ) ;;
151 if [ -z "${output// /}" ]; then
157 function grabdata_desc() {
161 version) output=$( grep -e "^\
[V\
]" $1 | cut -d' ' -f2- ) ;;
166 function grabdata_cache() {
170 status) if grep -q -e "^\
[.
-ERROR\
]" $1; then
175 size) output=$( grep -e "^\
[SIZE\
]" $1 | cut -d' ' -f2- ) ;;
180 function compare_package() {
182 local fullpkg=${1##*/package/}
184 local target= x= missing=0
187 local srcver= srcstatus= srcsize=
188 local tgtver= tgtstatus= tgtsize=
192 [ $ignrepo -eq 1 ] && fullpkg=$pkg
194 srcver=$( grabdata $source $pkg version )
195 srcstatus=$( grabdata $source $pkg status )
196 srcsize=$( grabdata $source $pkg size )
202 target=$( echo $x/package/*/$pkg | head -n 1 )
203 if [ -d "$target" ]; then
204 tgtver="$tgtver:$
( grabdata
$target $pkg version
)"
205 tgtstatus="$tgtstatus:$
( grabdata
$target $pkg status
)"
206 tgtsize="$tgtsize:$
( grabdata
$target $pkg size
)"
208 tgtver="$tgtver:MISSING
"
209 tgtstatus="$tgtstatus:MISSING
"
210 tgtsize="$tgtsize:MISSING
"
216 tgtstatus="${tgtstatus#:}"
217 tgtsize="${tgtsize#:}"
219 # do we have different versions?
221 equalver=1 equalstatus=1
222 IFS=':' ; for x in $tgtver; do
223 [ "$x" != "$srcver" ] && equalver=0
225 IFS=':' ; for x in $tgtstatus; do
226 [ "$x" != "$srcstatus" ] && equalstatus=0
229 # optimize version and status if they are the same
231 if [ $equalver -eq 1 ]; then
234 version="$srcver -> $tgtver"
237 if [ $equalstatus -eq 1 ]; then
240 status="$srcstatus -> $tgtstatus"
243 # acording to verbosity level, what info should i show?
245 if [ $verbose -eq 0 ]; then
248 info="($version) ($status) ($srcsize -> $tgtsize)"
251 if [ $missing -eq 1 ]; then
252 if [ $quiet -le 1 ]; then
253 # New - the package is not available at target tree
254 echo "N
$fullpkg $info" 1>&2
255 [ $dopatch -eq 1 ] && diff_package $source $target
257 elif [ $equalver -eq 1 ]; then
258 if [ $quiet -eq 0 ]; then
259 # Equal - the versions and cache status are the same on both trees
260 echo "E
$fullpkg $info" 1>&2
261 [ $dopatch -eq 1 ] && diff_package $source $target
264 # Modified - the version on both trees is different
265 echo "M
$fullpkg $info" 1>&2
266 [ $dopatch -eq 1 ] && diff_package $source $target
270 if [ -z "$source" -o -z "$targets" ]; then
275 for x in $source $targets; do
276 [ ! -d "$x/" ] && allexist=0; break
279 if [ $allexist -eq 1 ]; then
280 echo -e "from
: $source\nto..
: $targets" 1>&2
282 if [ "$repositories" ]; then
283 for repo in $repositories; do
284 for x in $source/package/$repo/*; do
285 [ -d "$x" ] && ( compare_package $x $targets )
288 elif [ "$packages" ]; then
289 for pkg in $packages; do
290 x=$( echo $source/package/*/$pkg | head -n 1 )
291 [ -d "$x" ] && compare_package $x $targets
294 for repo in $source/package/*; do
296 [ -d "$x" ] && compare_package $x $targets