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.

151 lines
3.8 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. set -e
  19. [ -n "$SDEROOT" ] ||
  20. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  21. . $SDEROOT/lib/libsde.in
  22. # svn or svk ?
  23. #
  24. if [ -d $SDEROOT/.svn/ ]; then
  25. SVN=svn
  26. else
  27. SVN=svk
  28. fi
  29. locations= x= y=
  30. logfile=
  31. tmpfile=$SDEROOT/tmp/$$
  32. mkdir -p "$SDEROOT/tmp"
  33. if [ "$1" == "--file" ]; then
  34. logfile="`readlink -f $2 2> /dev/null`"; shift; shift;
  35. fi
  36. # validate locations
  37. #
  38. for x; do
  39. if [ -z "$x" ]; then
  40. continue
  41. elif [ -e "$x" ]; then
  42. # exists, normalize
  43. y="$( readlink -f $x )"
  44. if [ "$y" == "${y#$SDEROOT}" ]; then
  45. echo_warning "'$COLOR_MESSAGE$x$COLOR_NORMAL'" \
  46. "is out of the tree, skipping."
  47. continue
  48. fi
  49. x="${y#$SDEROOT/}"
  50. elif [ -e "$SDEROOT/$x" ]; then
  51. # root relative
  52. true
  53. elif [ -d "$( echo "$SDEROOT/package/"*"/$x" )" ]; then
  54. # package from this tree
  55. x="$( cd "$SDEROOT"; echo "package/"*"/$x" )"
  56. elif [ -n "$( $SVN st "$x" 2> /dev/null )" ]; then
  57. # oh, it use was deleted
  58. y="$PWD/$x"
  59. y="$( readlink -f ${y%/*} )"
  60. if [ "$y" == "${y#$SDEROOT}" ]; then
  61. echo_warning "'$COLOR_MESSAGE$x$COLOR_NORMAL'" \
  62. "is out of the tree, skipping."
  63. continue
  64. fi
  65. x="${y#$SDEROOT/}/${x##*/}"
  66. else
  67. echo_warning "'$COLOR_MESSAGE$x$COLOR_NORMAL' not found, skipping."
  68. continue
  69. fi
  70. locations="$locations $x"
  71. done
  72. if [ -z "$( echo $locations )" ]; then
  73. echo_abort 1 "No locations, bye."
  74. fi
  75. if [ -n "$logfile" -a ! -r "$logfile" ]; then
  76. echo_abort 2 "File '$logfile' not found."
  77. fi
  78. # and here we go
  79. #
  80. trap 'echo_error "Got SIGINT (Crtl-C)." ; rm $tmpfile.status $tmpfile.diff ; [ $logfile != $tmpfile.log ] || rm $logfile; exit 1' INT
  81. cd "$SDEROOT"
  82. (
  83. $SVN st $locations | tee $tmpfile.status | grep '^\(A\|M\)' | tr -s ' ' | cut -d' ' -f2- | while read f; do
  84. f=${f#+ }
  85. if [ -f "$f" ]; then
  86. $SDEROOT/lib/sde-package/patch-copyright.sh "$f"
  87. fi
  88. done | patch -p0 2> /dev/null || true
  89. )
  90. echo_msg "Changes:"
  91. $SVN diff $locations | tee $tmpfile.diff
  92. if [ -z "$logfile" ]; then
  93. logfile=$tmpfile.log
  94. # the grep -v === is a hack - somehow the svn === lines confuse awk ... ?!?
  95. grep -v === $tmpfile.diff |
  96. awk -f $SDEROOT/lib/sde-commit/commit-message.awk > $logfile
  97. fi
  98. echo_msg "Status:"
  99. cat $tmpfile.status
  100. if [ -s $tmpfile.diff ] || grep -q '^A' $tmpfile.status; then
  101. quit=0
  102. until [ $quit -ne 0 ]; do
  103. echo_msg "Commit Message:"
  104. if [ -s $logfile ]; then
  105. cat $logfile
  106. commit=",${COLOR_MESSAGE}c${COLOR_NORMAL}:commit"
  107. else
  108. echo_warning "\tEmpty Log File!"
  109. commit=
  110. fi
  111. echo -en "\n${COLOR_MESSAGE}Is the message ok?${COLOR_NORMAL}"
  112. 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} "
  113. read opt
  114. case "$opt" in
  115. c*) if [ -n "$commit" ]; then
  116. $SVN commit $locations --file $logfile && rm "$logfile" ; quit=1
  117. fi ;;
  118. d*) less $tmpfile.diff ;;
  119. s*) cat $tmpfile.status ;;
  120. e*) ${EDITOR:-vi} $logfile ;;
  121. q*) quit=1 ;;
  122. *) echo "Excuse me?"
  123. esac
  124. done
  125. else
  126. echo_warning "No changes detected at:$locations"
  127. fi
  128. rm -f $tmpfile.status $tmpfile.diff
  129. [ "$logfile" != "$tmpfile.log" ] || rm -f "$logfile"