* updated pyxdg (0.19 -> 0.28)
[t2sde.git] / scripts / Commit
blob14b8250f7d29f4d9687ae88bd6f5c5d385b16311
1 #!/usr/bin/env bash
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # T2 SDE: scripts/Commit
4 # Copyright (C) 2004 - 2024 The T2 SDE Project
5 #
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
13 force=
14 cache=
15 svnopt=
16 addtxt=
17 fold=
18 untested=
20 locations=
21 while [ "$1" ]; do
22 case "$1" in
23 -f) force=1 ;;
24 -u|-untested) untested=1 ;;
25 -svn-opt)
26 svnopt="$2"; shift ;;
27 -add-txt)
28 addtxt="$2"; shift ;;
29 -cache)
30 cache=1 ;;
31 -fold)
32 fold=1 ;;
34 [ ! -e "$1" -a -e `echo package/*/$1` ] &&
35 x=`echo package/*/$1` || x="$1"
36 locations="$locations $x"
38 esac
39 shift
40 done
42 if [ -z "$locations" ]; then
43 echo "Usage $0 package | files"
44 exit
47 cleanup() {
48 local ret=$?
49 rm $$.{log,diff}
50 return 0
52 trap cleanup EXIT
54 fold_desc() {
55 # save out [T], fold and insert with appropriate newlines
56 sed -n '/\[T\] \(.*\)/{s//\1/; H}; ${x; s/\n/ /g; s/^ //; p}' "$1" |
57 fold -w 76 -s | sed 's/^/[T] /; s/ */ /g; s/ $//' > x
58 sed "/^\[I\].*/{ s//&\n/; r x
59 }; /^\[T\]/d" $1 | sed '/^$/{n;/^$/d}' > x.2
60 cat x.2 > $f
61 rm -f x x.2
64 trap 'echo "Got SIGINT (Ctrl-C)."; exit 1' INT
66 # Copy .caches if requested
68 [ "$cache" ] &&
69 for p in $locations; do
70 [[ $p != *package/*/* ]] && continue
71 p=${p#*package/*/}
72 p=${p%%/*}
73 d=$(echo package/*/$p)
74 cp -vf /var/adm/cache/$p $d/$p.cache
75 unset p d
76 done
78 # CopyPatch and Checksum and CkSumPatch
80 svn st $locations | grep '^\(A\|M\)' | cut -c8- | while read f; do
81 if [ -f "$f" ]; then
82 scripts/Create-CopyPatch $f | patch -p0
83 if [[ $f = *.desc ]]; then
84 [ "$fold" ] && fold_desc $f
85 if grep '\[D\] \+0 \+' $f; then
86 pkg=${f%.desc} pkg=${pkg##*/}
87 scripts/Create-CkSumPatch $pkg | patch -p0
91 done
93 visualize_warnings() {
94 # do not highlight just single space diff lines
95 sed '/^[+ -]./ {
96 s/\([[ \r\t]]*\)$/\o033[0;41m\1\o033[0m/
97 s/\( *\)/\o033[0;41m\1\o033[0m/
101 echo "Diff:"
102 svn diff $locations | tee $$.diff | visualize_warnings
104 # the grep -v === is a hack - somehow the svn === lines confuse awk ... ?!?
105 grep -v === $$.diff | gawk "
106 BEGIN { FS=\"[ /]\" }
108 /^\+\+\+ / { pkg = \$4 }
109 { if (sub(/^\+\[I\]/,\" -\") ) { info = \$0 } }
111 /^\-\[V\] / { oldver=\$2 }
112 /^\+\[V\] / {
113 newver=\$2
114 if (oldver)
115 print \"\t* updated \" pkg \" (\" oldver \" -> \" newver \")\"
116 else {
117 print \"\t* added \" pkg \" (\" newver \")\" info
119 oldver=\"\"; newver=\"\"; info=\"\"
122 /^\-\[P\] / { oldprio=\$4 }
123 /^\+\[P\] / {
124 newprio=\$4
125 if (oldprio)
126 print \"\t* changed \" pkg \" build priority (\" oldprio \" -> \" newprio \")\"
127 oldprio=\"\"; newprior=\"\"
130 " > $$.log
132 [ "$untested" ] && sed -i -z 's/\n$/, untested\n/g' $$.log
134 [ "$addtxt" ] && sed -i "\$s|\$|$addtxt|" $$.log
136 commit() {
137 svn commit $svnopt $locations --file $$.log || exit $?
140 if [ -s $$.diff ]; then
141 quit=0
142 until [ $quit -ne 0 ]; do
144 echo -e "\nLog:"
145 if [ -s $$.log ]; then
146 cat $$.log
147 commit=",c=commit"
148 else
149 echo -e "\tEmpty Log File!"
150 commit=
153 echo -en "\nLog ok (q=quit,e=edit,d=diff,s=status$commit)? "
154 [ ! "$force" ] && read in || in="commit"
156 case "$in" in
157 c*) if [ -n "$commit" ]; then
158 commit; quit=1
159 fi ;;
160 d*) cat $$.diff | visualize_warnings | less -R ;;
161 s*) svn st $locations ;;
162 e*) ${EDITOR:-vi} $$.log ;;
163 q*) quit=1 ;;
164 *) echo "Excuse me?"
165 esac
166 done
167 else
168 echo -e "\nNo changes detected at:$locations"
169 svn st $locations