* mark python sqlite DEP opt and update .cache
[t2sde.git] / scripts / Commit
bloba7af1f6dd38386799359eb11198a05427fee2295
1 #!/usr/bin/env bash
2 # --- T2-COPYRIGHT-BEGIN ---
3 # t2/scripts/Commit
4 # Copyright (C) 2004 - 2025 The T2 SDE Project
5 # SPDX-License-Identifier: GPL-2.0
6 # --- T2-COPYRIGHT-END ---
8 force=
9 svnopt=
10 addtxt=
11 fold=
12 untested=
13 cache=
14 root=
16 locations=
17 while [ "$1" ]; do
18 case "$1" in
19 -f) force=1 ;;
20 -u|-untested) untested=1 ;;
21 -svn-opt)
22 svnopt="$2"; shift ;;
23 -add-txt)
24 addtxt="$2"; shift ;;
25 -cache)
26 ((cache++)) ;;
27 -root)
28 root="$2"; shift ;;
29 -fold)
30 fold=1 ;;
32 [ ! -e "$1" -a -e `echo package/*/$1` ] &&
33 x=`echo package/*/$1` || x="$1"
34 locations="$locations $x"
36 esac
37 shift
38 done
40 if [ -z "$locations" ]; then
41 echo "Usage $0 [ -cache ] [ -fold ] package | files"
42 exit
45 cleanup() {
46 local ret=$?
47 rm $$.{log,diff}
48 return 0
50 trap cleanup EXIT
52 fold_desc() {
53 # save out [T], fold and insert with appropriate newlines
54 sed -n '/\[T\] \(.*\)/{s//\1/; H}; ${x; s/\n/ /g; s/^ //; p}' "$1" |
55 fold -w 76 -s | sed 's/^/[T] /; s/ */ /g; s/ $//' > x
56 sed "/^\[I\].*/{ s//&\n/; r x
57 }; /^\[T\]/d" $1 | sed '/^$/{n;/^$/d}' > x.2
58 cat x.2 > $f
59 rm -f x x.2
62 trap 'echo "Got SIGINT (Ctrl-C)."; exit 1' INT
64 # Copy .caches if requested and changed significantly
66 [ "$cache" ] &&
67 for p in $locations; do
68 [[ $p != *package/*/* ]] && continue
69 p=${p#*package/*/}
70 p=${p%%/*}
71 d=$(echo package/*/$p)
72 # changed enough?
73 if [ -e $d/$p.cache -a -e $root/var/adm/cache/$p ]; then
74 # changes of DEP/OPT content, if not enforced
75 changes=$(diff -u $d/$p.cache $root/var/adm/cache/$p | sed -n '/^[+-]\[...\]/p' | wc -l)
76 [ $changes -le 1 -a $cache -lt 2 ] && continue
78 cp -vf $root/var/adm/cache/$p $d/$p.cache
79 unset p d
80 done
82 # CopyPatch and Checksum and CkSumPatch
84 svn st $locations | grep '^\(A\|M\)' | cut -c8- | while read f; do
85 if [ -f "$f" ]; then
86 scripts/Create-CopyPatch $f | patch -p0
87 if [[ $f = *.desc ]]; then
88 [ "$fold" ] && fold_desc $f
89 if grep '\[D\] \+0 \+' $f; then
90 pkg=${f%.desc} pkg=${pkg##*/}
91 scripts/Create-CkSumPatch $pkg | patch -p0
95 done
97 visualize_warnings() {
98 # do not highlight just single space diff lines
99 sed '/^[+ -]./ {
100 s/\([[ \r\t]]*\)$/\o033[0;41m\1\o033[0m/
101 s/\( *\)/\o033[0;41m\1\o033[0m/
105 echo "Diff:"
106 svn diff $locations | tee $$.diff | visualize_warnings
108 # the grep -v === is a hack - somehow the svn === lines confuse awk ... ?!?
109 grep -v === $$.diff | gawk "
110 BEGIN { FS=\"[ /]\" }
112 /^\+\+\+ / { pkg = \$4 }
113 { if (sub(/^\+\[I\]/,\" -\") ) { info = \$0 } }
115 /^\-\[V\] / { oldver=\$2 }
116 /^\+\[V\] / {
117 newver=\$2
118 if (oldver)
119 print \"\t* updated \" pkg \" (\" oldver \" -> \" newver \")\"
120 else {
121 print \"\t* added \" pkg \" (\" newver \")\" info
123 oldver=\"\"; newver=\"\"; info=\"\"
126 /^\-\[P\] / { oldprio=\$4 }
127 /^\+\[P\] / {
128 newprio=\$4
129 if (oldprio)
130 print \"\t* changed \" pkg \" build priority (\" oldprio \" -> \" newprio \")\"
131 oldprio=\"\"; newprior=\"\"
134 " > $$.log
136 [ "$untested" ] && sed -i -z 's/\n$/, untested\n/g' $$.log
138 [ "$addtxt" ] && sed -i "\$s|\$|$addtxt|" $$.log
140 commit() {
141 svn commit $svnopt $locations --file $$.log || exit $?
144 if [ -s $$.diff ]; then
145 quit=0
146 until [ $quit -ne 0 ]; do
148 echo -e "\nLog:"
149 if [ -s $$.log ]; then
150 cat $$.log
151 commit=",c=commit"
152 else
153 echo -e "\tEmpty Log File!"
154 commit=
157 echo -en "\nLog ok (q=quit,e=edit,d=diff,s=status$commit)? "
158 [ ! "$force" ] && read in || in="commit"
160 case "$in" in
161 c*) if [ -n "$commit" ]; then
162 commit; quit=1
163 fi ;;
164 d*) cat $$.diff | visualize_warnings | less -R ;;
165 s*) svn st $locations ;;
166 e*) ${EDITOR:-vi} $$.log ;;
167 q*) quit=1 ;;
168 *) echo "Excuse me?"
169 esac
170 done
171 else
172 echo -e "\nNo changes detected at:$locations"
173 svn st $locations