#!/usr/bin/env bash # --- T2-COPYRIGHT-NOTE-BEGIN --- # T2 SDE: scripts/Commit # Copyright (C) 2004 - 2024 The T2 SDE Project # # This Copyright note is generated by scripts/Create-CopyPatch, # more information can be found in the files COPYING and README. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2. # --- T2-COPYRIGHT-NOTE-END --- force= cache= svnopt= addtxt= untested= locations= while [ "$1" ]; do case "$1" in -f) force=1 ;; -u|-untested) untested=1 ;; -svn-opt) svnopt="$2"; shift ;; -add-txt) addtxt="$2"; shift ;; -cache) cache=1 ;; *) [ ! -e "$1" -a -e `echo package/*/$1` ] && x=`echo package/*/$1` || x="$1" locations="$locations $x" ;; esac shift done if [ -z "$locations" ]; then echo "Usage $0 package | files" exit fi cleanup() { local ret=$? rm $$.{log,diff} return 0 } trap cleanup EXIT trap 'echo "Got SIGINT (Ctrl-C)."; exit 1' INT # Copy .caches if requested # [ "$cache" ] && for p in $locations; do [[ $p != *package/*/* ]] && continue p=${p#*package/*/} p=${p%%/*} d=$(echo package/*/$p) cp -vf /var/adm/cache/$p $d/$p.cache unset p d done # CopyPatch and Checksum and CkSumPatch # svn st $locations | grep '^\(A\|M\)' | cut -c8- | while read f; do if [ -f "$f" ]; then scripts/Create-CopyPatch $f | patch -p0 if [[ $f = *.desc ]] && grep '\[D\] \+0 \+' $f; then pkg=${f%.desc} pkg=${pkg##*/} scripts/Create-CkSumPatch $pkg | patch -p0 fi fi done visualize_warnings() { # do not highlight just single space diff lines sed '/^[+ -]./ { s/\([[ \r\t]]*\)$/\o033[0;41m\1\o033[0m/ s/\( *\)/\o033[0;41m\1\o033[0m/ }' } echo "Diff:" svn diff $locations | tee $$.diff | visualize_warnings # the grep -v === is a hack - somehow the svn === lines confuse awk ... ?!? grep -v === $$.diff | gawk " BEGIN { FS=\"[ /]\" } /^\+\+\+ / { pkg = \$4 } { if (sub(/^\+\[I\]/,\" -\") ) { info = \$0 } } /^\-\[V\] / { oldver=\$2 } /^\+\[V\] / { newver=\$2 if (oldver) print \"\t* updated \" pkg \" (\" oldver \" -> \" newver \")\" else { print \"\t* added \" pkg \" (\" newver \")\" info } oldver=\"\"; newver=\"\"; info=\"\" } /^\-\[P\] / { oldprio=\$4 } /^\+\[P\] / { newprio=\$4 if (oldprio) print \"\t* changed \" pkg \" build priority (\" oldprio \" -> \" newprio \")\" oldprio=\"\"; newprior=\"\" } " > $$.log [ "$untested" ] && sed -i -z 's/\n$/, untested\n/g' $$.log [ "$addtxt" ] && sed -i "\$s|\$|$addtxt|" $$.log commit() { svn commit $svnopt $locations --file $$.log || exit $? } if [ -s $$.diff ]; then quit=0 until [ $quit -ne 0 ]; do echo -e "\nLog:" if [ -s $$.log ]; then cat $$.log commit=",c=commit" else echo -e "\tEmpty Log File!" commit= fi echo -en "\nLog ok (q=quit,e=edit,d=diff,s=status$commit)? " [ ! "$force" ] && read in || in="commit" case "$in" in c*) if [ -n "$commit" ]; then commit; quit=1 fi ;; d*) cat $$.diff | visualize_warnings | less -R ;; s*) svn st $locations ;; e*) ${EDITOR:-vi} $$.log ;; q*) quit=1 ;; *) echo "Excuse me?" esac done else echo -e "\nNo changes detected at:$locations" svn st $locations fi