# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# Filename: lib/sde-commit.in
|
|
# Copyright (C) 2006 - 2007 The OpenSDE Project
|
|
# Copyright (C) 2004 - 2006 The T2 SDE Project
|
|
#
|
|
# 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 as published by
|
|
# the Free Software Foundation; version 2 of the License. A copy of the
|
|
# GNU General Public License can be found in the file COPYING.
|
|
# --- SDE-COPYRIGHT-NOTE-END ---
|
|
|
|
#Description: Commits into svn the changes on the given locations
|
|
#Alias: ci
|
|
|
|
commit_usage() {
|
|
cat <<EOT
|
|
Usage: sde commit [--file <file>] <package> [<location> [...]] (Alias: ci)
|
|
|
|
Note: location can be a package name or an explicit file/directory
|
|
EOT
|
|
}
|
|
|
|
# svn or svk ?
|
|
#
|
|
if [ -d $SDEROOT/.svn/ ]; then
|
|
SVN=svn
|
|
else
|
|
SVN=svk
|
|
fi
|
|
|
|
# commit_main <locations>
|
|
#
|
|
commit_main() {
|
|
local locations= x= y=
|
|
local logfile=
|
|
|
|
if [ "$1" == "--file" ]; then
|
|
logfile="`readlink -f $2 2> /dev/null`"; shift; shift;
|
|
fi
|
|
|
|
# validate locations
|
|
#
|
|
for x; do
|
|
if [ -z "$x" ]; then
|
|
continue
|
|
elif [ -e "$x" ]; then
|
|
# exists, normalize
|
|
y="$( readlink -f $x )"
|
|
if [ "$y" == "${y#$SDEROOT}" ]; then
|
|
echo_warning "'$COLOR_MESSAGE$x$COLOR_NORMAL'" \
|
|
"is out of the tree, skipping."
|
|
continue
|
|
fi
|
|
x="${y#$SDEROOT/}"
|
|
elif [ -e "$SDEROOT/$x" ]; then
|
|
# root relative
|
|
true
|
|
elif [ -d "$( echo "$SDEROOT/package/"*"/$x" )" ]; then
|
|
# package from this tree
|
|
x="$( cd "$SDEROOT"; echo "package/"*"/$x" )"
|
|
elif [ -n "$( $SVN st "$x" 2> /dev/null )" ]; then
|
|
# oh, it use was deleted
|
|
y="$PWD/$x"
|
|
y="$( readlink -f ${y%/*} )"
|
|
if [ "$y" == "${y#$SDEROOT}" ]; then
|
|
echo_warning "'$COLOR_MESSAGE$x$COLOR_NORMAL'" \
|
|
"is out of the tree, skipping."
|
|
continue
|
|
fi
|
|
x="${y#$SDEROOT/}/${x##*/}"
|
|
else
|
|
echo_warning "'$COLOR_MESSAGE$x$COLOR_NORMAL' not found, skipping."
|
|
continue
|
|
fi
|
|
|
|
locations="$locations $x"
|
|
done
|
|
|
|
if [ -z "$( echo $locations )" ]; then
|
|
echo_abort 1 "No locations, bye."
|
|
fi
|
|
|
|
if [ -n "$logfile" -a ! -r "$logfile" ]; then
|
|
echo_abort 2 "File '$logfile' not found."
|
|
fi
|
|
|
|
# and here we go
|
|
#
|
|
trap 'echo_error "Got SIGINT (Crtl-C)." ; rm $$.status $$.diff ; [ $logfile != $$.log ] || rm $logfile; exit 1' INT
|
|
cd "$SDEROOT"
|
|
|
|
set +e
|
|
$SVN st $locations | tee $$.status | grep '^\(A\|M\)' | tr -s ' ' | cut -d' ' -f2- | while read f; do
|
|
f=${f#+ }
|
|
if [ -f "$f" ]; then
|
|
$SDEROOT/lib/sde-package/patch-copyright.sh "$f"
|
|
fi
|
|
done | patch -p0 2> /dev/null
|
|
set -e
|
|
|
|
echo_msg "Changes:"
|
|
$SVN diff $locations | tee $$.diff
|
|
|
|
if [ -z "$logfile" ]; then
|
|
logfile=$$.log
|
|
# the grep -v === is a hack - somehow the svn === lines confuse awk ... ?!?
|
|
grep -v === $$.diff |
|
|
awk -f $SDEROOT/lib/sde-commit/commit-message.awk > $logfile
|
|
fi
|
|
|
|
echo_msg "Status:"
|
|
cat $$.status
|
|
|
|
if [ -s $$.diff ] || grep -q '^A' $$.status; then
|
|
quit=0
|
|
until [ $quit -ne 0 ]; do
|
|
|
|
echo_msg "Commit Message:"
|
|
if [ -s $logfile ]; then
|
|
cat $logfile
|
|
commit=",${COLOR_MESSAGE}c${COLOR_NORMAL}:commit"
|
|
else
|
|
echo_warning "\tEmpty Log File!"
|
|
commit=
|
|
fi
|
|
|
|
echo -en "\n${COLOR_MESSAGE}Is the message ok?${COLOR_NORMAL}"
|
|
echo -en " (${COLOR_MESSAGE}q${COLOR_NORMAL}:quit,${COLOR_MESSAGE}e${COLOR_NORMAL}:edit,${COLOR_MESSAGE}d${COLOR_NORMAL}:diff,${COLOR_MESSAGE}s${COLOR_NORMAL}:status$commit)${COLOR_MESSAGE}:${COLOR_NORMAL} "
|
|
read in
|
|
|
|
case "$in" in
|
|
c*) if [ -n "$commit" ]; then
|
|
$SVN commit $locations --file $logfile && rm "$logfile" ; quit=1
|
|
fi ;;
|
|
d*) less $$.diff ;;
|
|
s*) cat $$.status ;;
|
|
e*) ${EDITOR:-vi} $logfile ;;
|
|
q*) quit=1 ;;
|
|
*) echo "Excuse me?"
|
|
esac
|
|
done
|
|
else
|
|
echo_warning "No changes detected at:$locations"
|
|
fi
|
|
|
|
rm -f $$.status $$.diff
|
|
[ "$logfile" != "$$.log" ] || rm -f "$logfile"
|
|
}
|
|
|
|
if [ "$module" == "commit" ]; then
|
|
if [ $# -gt 0 ]; then
|
|
commit_main "$@"
|
|
else
|
|
commit_usage
|
|
exit 1
|
|
fi
|
|
fi
|