OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
3.7 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: lib/sde-commit.in
  6. # Copyright (C) 2006 - 2007 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. #
  9. # More information can be found in the files COPYING and README.
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; version 2 of the License. A copy of the
  14. # GNU General Public License can be found in the file COPYING.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. #Description: Commits into svn the changes on the given locations
  17. #Alias: ci
  18. [ -n "$SDEROOT" ] ||
  19. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  20. . $SDEROOT/lib/libsde.in
  21. commit_usage() {
  22. local progname=${0##*/}
  23. cat <<EOT
  24. Usage: $progname [--file <message file>] [FILES...]
  25. EOT
  26. }
  27. shortopts='F:'
  28. longopts='file:'
  29. options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
  30. if [ $? -ne 0 ]; then
  31. commit_usage
  32. exit -1
  33. fi
  34. # load new arguments list
  35. eval set -- "$options"
  36. logfile=
  37. tmpfile=$SDEROOT/tmp/$$
  38. mkdir -p "$SDEROOT/tmp"
  39. while [ $# -gt 0 ]; do
  40. case "$1" in
  41. -F|--file) logfile="`readlink -f $2 2> /dev/null`"; shift ;;
  42. --) shift; break ;;
  43. *) echo_abort 1 "Unknown argument '$1', aborting."
  44. esac
  45. shift
  46. done
  47. if [ -n "$logfile" -a ! -r "$logfile" ]; then
  48. echo_abort 2 "File '$logfile' not found."
  49. fi
  50. # validate locations
  51. #
  52. [ $# -gt 0 ] || set -- .
  53. # extract roots at root relative paths of the given locations
  54. locations=$( $SDEROOT/bin/sde-list-files --roots "$@" )
  55. # we only accept one root at the time
  56. roots=$( echo "$locations" | cut -d' ' -f1 | sort -u )
  57. root=$( echo "$roots" | head -n 1 )
  58. [ "$root" == "$roots" ] || echo_abort 1 "Locations from multiple repositories given, aborting."
  59. # $root relative locations
  60. locations=$( echo "$locations" | cut -d' ' -f2 )
  61. [ -n "$locations" ] || echo_abort 1 "No locations, aborting."
  62. echo_abort 0 "Not yet reimplemented."
  63. # and here we go
  64. #
  65. trap 'echo_error "Got SIGINT (Crtl-C)." ; rm $tmpfile.status $tmpfile.diff ; [ $logfile != $tmpfile.log ] || rm $logfile; exit 1' INT
  66. cd "$SDEROOT"
  67. (
  68. $SVN st $locations | tee $tmpfile.status | grep '^\(A\|M\)' | tr -s ' ' | cut -d' ' -f2- | while read f; do
  69. f=${f#+ }
  70. if [ -f "$f" ]; then
  71. $SDEROOT/lib/sde-package/patch-copyright.sh "$f"
  72. fi
  73. done | patch -p0 2> /dev/null || true
  74. )
  75. echo_msg "Changes:"
  76. $SVN diff $locations | tee $tmpfile.diff
  77. if [ -z "$logfile" ]; then
  78. logfile=$tmpfile.log
  79. # the grep -v === is a hack - somehow the svn === lines confuse awk ... ?!?
  80. grep -v === $tmpfile.diff |
  81. awk -f $SDEROOT/lib/sde-commit/commit-message.awk > $logfile
  82. fi
  83. echo_msg "Status:"
  84. cat $tmpfile.status
  85. if [ -s $tmpfile.diff ] || grep -q '^A' $tmpfile.status; then
  86. quit=0
  87. until [ $quit -ne 0 ]; do
  88. echo_msg "Commit Message:"
  89. if [ -s $logfile ]; then
  90. cat $logfile
  91. commit=",${COLOR_MESSAGE}c${COLOR_NORMAL}:commit"
  92. else
  93. echo_warning "\tEmpty Log File!"
  94. commit=
  95. fi
  96. echo -en "\n${COLOR_MESSAGE}Is the message ok?${COLOR_NORMAL}"
  97. 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} "
  98. read opt
  99. case "$opt" in
  100. c*) if [ -n "$commit" ]; then
  101. $SVN commit $locations --file $logfile && rm "$logfile" ; quit=1
  102. fi ;;
  103. d*) less $tmpfile.diff ;;
  104. s*) cat $tmpfile.status ;;
  105. e*) ${EDITOR:-vi} $logfile ;;
  106. q*) quit=1 ;;
  107. *) echo "Excuse me?"
  108. esac
  109. done
  110. else
  111. echo_warning "No changes detected at:$locations"
  112. fi
  113. rm -f $tmpfile.status $tmpfile.diff
  114. [ "$logfile" != "$tmpfile.log" ] || rm -f "$logfile"