mkCTM revision 3833
12886Sphk#!/usr/local/bin/tclsh 22886Sphk 32926Sphkset CTMignoreCVS 0 42926Sphkset CTMapply 1 53833Sphkset CTMdont {^///} 62926Sphk 72886Sphksource $argv 82886Sphk 93833Sphkcd /u1/CTM/SW 103833Sphk 112886Sphkset tmp $CTMtmp 122886Sphkset dd $CTMdest 132886Sphkset d1 $CTMcopy 142886Sphkset d2 $CTMref 152886Sphkset foo $CTMdate 162886Sphkset foo $CTMprefix 172886Sphkset foo $CTMname 182886Sphk 193112Sphkexec sh -x -c "rm -f ${tmp}.*" >&@ stdout 202886Sphk 212886Sphkset f1 [open "| ./ctm_scan $d1"] 222886Sphkset f2 [open "| ./ctm_scan $d2"] 232886Sphk 242886Sphkset fo_del [open $tmp.del w] 252886Sphkset fo_rmdir [open $tmp.rmdir w] 262886Sphkset fo_mkdir [open $tmp.mkdir w] 272886Sphkset fo_files [open $tmp.files w] 282886Sphkset changes 0 292886Sphk 302886Sphk#### 312886Sphk# Find CTM# 322886Sphkfor {set i 0} {1} {incr i} { 332886Sphk if {[file exists [format "%s/$CTMname.%04d" $dd $i]]} continue 342886Sphk if {[file exists [format "%s/$CTMname.%04d.gz" $dd $i]]} continue 352886Sphk break 362886Sphk} 372886Sphkset CTMnbr $i 382886Sphk 392886Sphkputs "Doing CTMname $CTMname CTMnbr $CTMnbr CTMdate $CTMdate" 402886Sphk 412886Sphk##### 422886Sphk# Type Name Mode User Group Barf Size Hash 432886Sphk 442886Sphkproc CTMadd {t n m u g b s h} { 452886Sphk global fo_files fo_mkdir changes d2 462886Sphk puts stderr "A $b $t $n" 472886Sphk if {$t == "d"} { 482886Sphk puts $fo_mkdir "CTMDM $n $u $g $m" 492886Sphk incr changes 502886Sphk return 512886Sphk } 522886Sphk puts $fo_files "CTMFM $n $u $g $m $h $s" 532886Sphk flush $fo_files 542886Sphk exec cat $d2/$n >@ $fo_files 552886Sphk puts $fo_files "" 562886Sphk incr changes 572886Sphk return 582886Sphk} 592886Sphkproc CTMdel {t n m u g b s h} { 602886Sphk global fo_del fo_rmdir changes 612886Sphk puts stderr "D $b $t $n" 622886Sphk if {$t == "d"} { 632886Sphk puts $fo_rmdir "CTMDR $n" 642886Sphk incr changes 652886Sphk return 662886Sphk } 672886Sphk puts $fo_del "CTMFR $n $h" 682886Sphk incr changes 692886Sphk return 702886Sphk} 712886Sphkproc CTMchg {t1 n1 m1 u1 g1 b1 s1 h1 t2 n2 m2 u2 g2 b2 s2 h2} { 722886Sphk global fo_files d2 d1 changes 732886Sphk if {$t1 == "d" && $t2 == "d"} { 742886Sphk return 752886Sphk } 762886Sphk if {$t1 == "d" || $t2 == "d"} { 772886Sphk CTMdel $t1 $n1 $m1 $u1 $g1 $b1 $s1 $h1 782886Sphk CTMadd $t2 $n2 $m2 $u2 $g2 $b2 $s2 $h2 792886Sphk return 802886Sphk } 812886Sphk if {"x$h1" == "x$h2" && $s1 == $s2} { 822886Sphk return 832886Sphk puts stderr "M $b1$b2 $t1$t2 $n1" 842886Sphk puts $fo_files "CTMFA $n2 $u2 $g2 $m2 $h2" 852886Sphk incr changes 862886Sphk return 872886Sphk } 882948Sphk if {$b1 == "0" && $b2 == "0"} { 892971Sphk set i [catch "exec diff -n $d1/$n1 $d2/$n2 > tmp" j] 902926Sphk set s [file size tmp] 912926Sphk if {$s < $s2} { 923112Sphk puts stderr "E $b1$b2 $t1$t2 $n1" 932971Sphk puts $fo_files "CTMFN $n1 $u2 $g2 $m2 $h1 $h2 $s" 942926Sphk flush $fo_files 952926Sphk exec cat tmp >@ $fo_files 962926Sphk puts $fo_files "" 972926Sphk incr changes 982926Sphk return 992926Sphk } 1002886Sphk } 1012926Sphk puts stderr "R $b1$b2 $t1$t2 $n1" 1022926Sphk puts $fo_files "CTMFS $n2 $u2 $g2 $m2 $h1 $h2 $s2" 1032886Sphk flush $fo_files 1042926Sphk exec cat $d2/$n2 >@ $fo_files 1052886Sphk puts $fo_files "" 1062886Sphk incr changes 1072926Sphk return 1082886Sphk} 1092886Sphk##### 1102886Sphkset l1 "" 1112886Sphkset l2 "" 1122886Sphk 1132886Sphkwhile 1 { 1142886Sphk 1152886Sphk if {$l1 == ""} {gets $f1 l1} 1162886Sphk 1172886Sphk if {$l2 == ""} {gets $f2 l2} 1182886Sphk 1192886Sphk if {$l1 == "" && $l2 == ""} break 1202886Sphk 1212886Sphk set n1 [lindex $l1 1] 1222886Sphk set n2 [lindex $l2 1] 1232886Sphk 1243833Sphk #if {[regexp $CTMdont /$n1]} { set l1 "" ; continue } 1253833Sphk if {[regexp $CTMdont /$n2]} { set l2 "" ; continue } 1263833Sphk 1272886Sphk if {$l1 == $l2} { set l1 "" ; set l2 "" ; continue } 1282886Sphk 1292926Sphk if {$CTMignoreCVS } { 1302926Sphk if {[regexp {/CVS/} $l1]} {set l1 ""; continue } 1312926Sphk if {[regexp {/CVS/} $l2]} {set l2 ""; continue } 1322926Sphk } 1332926Sphk 1342886Sphk if {$l1 == "" } { eval CTMadd $l2 ; set l2 "" ; continue } 1352886Sphk 1362886Sphk if {$l2 == "" } { eval CTMdel $l1 ; set l1 "" ; continue } 1372886Sphk 1382886Sphk if {$n1 < $n2 } { eval CTMdel $l1 ; set l1 "" ; continue } 1392886Sphk 1402886Sphk if {$n1 > $n2 } { eval CTMadd $l2 ; set l2 "" ; continue } 1412886Sphk 1422886Sphk if {$n1 == $n2} { eval CTMchg $l1 $l2 ; set l1 "" ; set l2 "" ; continue } 1432886Sphk} 1442886Sphk 1452886Sphkclose $fo_del 1462886Sphkclose $fo_rmdir 1472886Sphkclose $fo_mkdir 1482886Sphkclose $fo_files 1492886Sphk 1502886Sphkexec echo CTM_BEGIN 2.0 $CTMname $CTMnbr $CTMdate $CTMprefix > $tmp.begin 1512886Sphkexec echo -n "CTM_END " >> $tmp.end 1522926Sphkset m [exec cat $tmp.begin $tmp.del $tmp.rmdir $tmp.mkdir $tmp.files $tmp.end | /sbin/md5] 1532886Sphkexec echo "$m" >> $tmp.end 1542886Sphk 1552886Sphkif {!$changes} { 1562886Sphk puts "no changes" 1573112Sphk exec sh -c "rm -f ${tmp}.*" 1582886Sphk exit 0 1592886Sphk} 1603112Sphkflush stdout 1613833Sphkset nm [format "%s.%04d" $CTMname $CTMnbr] 1622886Sphk 1633112Sphkexec cat $tmp.begin $tmp.del $tmp.rmdir $tmp.mkdir $tmp.files $tmp.end \ 1643833Sphk | gzip -9 > ${tmp}:${nm}.gz 1653112Sphk 1663112Sphkexec sh -x -c "rm -f ${tmp}.*" >&@ stdout 1673112Sphk 1682926Sphkif {$CTMapply} { 1693833Sphk exec sh -e -x -c "cd $CTMcopy ; /u1/CTM/SW/ctm -v -v -v ${tmp}:${nm}.gz" >&@ stdout 1702926Sphk} 1713833Sphkexec mv ${tmp}:${nm}.gz $dd/.tmp_${nm}.gz >&@ stdout 1723833Sphkexec mv $dd/.tmp_${nm}.gz $dd/${nm}.gz >&@ stdout 173