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.

161 lines
3.9 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: lib/sde-commit.in
  5. # Copyright (C) 2006 - 2007 The OpenSDE Project
  6. # Copyright (C) 2004 - 2006 The T2 SDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. #Description: Commits into svn the changes on the given locations
  16. #Alias: ci
  17. commit_usage() {
  18. cat <<EOT
  19. Usage: sde commit [--file <file>] <package> [<location> [...]] (Alias: ci)
  20. Note: location can be a package name or an explicit file/directory
  21. EOT
  22. }
  23. # svn or svk ?
  24. #
  25. if [ -d $SDEROOT/.svn/ ]; then
  26. SVN=svn
  27. else
  28. SVN=svk
  29. fi
  30. # commit_main <locations>
  31. #
  32. commit_main() {
  33. local locations= x= y=
  34. local logfile=
  35. if [ "$1" == "--file" ]; then
  36. logfile="`readlink -f $2 2> /dev/null`"; shift; shift;
  37. fi
  38. # validate locations
  39. #
  40. for x; do
  41. if [ -z "$x" ]; then
  42. continue
  43. elif [ -e "$x" ]; then
  44. # exists, normalize
  45. y="$( readlink -f $x )"
  46. if [ "$y" == "${y#$SDEROOT}" ]; then
  47. echo_warning "'$COLOR_MESSAGE$x$COLOR_NORMAL'" \
  48. "is out of the tree, skipping."
  49. continue
  50. fi
  51. x="${y#$SDEROOT/}"
  52. elif [ -e "$SDEROOT/$x" ]; then
  53. # root relative
  54. true
  55. elif [ -d "$( echo "$SDEROOT/package/"*"/$x" )" ]; then
  56. # package from this tree
  57. x="$( cd "$SDEROOT"; echo "package/"*"/$x" )"
  58. elif [ -n "$( $SVN st "$x" 2> /dev/null )" ]; then
  59. # oh, it use was deleted
  60. y="$PWD/$x"
  61. y="$( readlink -f ${y%/*} )"
  62. if [ "$y" == "${y#$SDEROOT}" ]; then
  63. echo_warning "'$COLOR_MESSAGE$x$COLOR_NORMAL'" \
  64. "is out of the tree, skipping."
  65. continue
  66. fi
  67. x="${y#$SDEROOT/}/${x##*/}"
  68. else
  69. echo_warning "'$COLOR_MESSAGE$x$COLOR_NORMAL' not found, skipping."
  70. continue
  71. fi
  72. locations="$locations $x"
  73. done
  74. if [ -z "$( echo $locations )" ]; then
  75. echo_abort 1 "No locations, bye."
  76. fi
  77. if [ -n "$logfile" -a ! -r "$logfile" ]; then
  78. echo_abort 2 "File '$logfile' not found."
  79. fi
  80. # and here we go
  81. #
  82. trap 'echo_error "Got SIGINT (Crtl-C)." ; rm $$.status $$.diff ; [ $logfile != $$.log ] || rm $logfile; exit 1' INT
  83. cd "$SDEROOT"
  84. set +e
  85. $SVN st $locations | tee $$.status | grep '^\(A\|M\)' | tr -s ' ' | cut -d' ' -f2- | while read f; do
  86. f=${f#+ }
  87. if [ -f "$f" ]; then
  88. $SDEROOT/lib/sde-package/patch-copyright.sh "$f"
  89. fi
  90. done | patch -p0 2> /dev/null
  91. set -e
  92. echo_msg "Changes:"
  93. $SVN diff $locations | tee $$.diff
  94. if [ -z "$logfile" ]; then
  95. logfile=$$.log
  96. # the grep -v === is a hack - somehow the svn === lines confuse awk ... ?!?
  97. grep -v === $$.diff |
  98. awk -f $SDEROOT/lib/sde-commit/commit-message.awk > $logfile
  99. fi
  100. echo_msg "Status:"
  101. cat $$.status
  102. if [ -s $$.diff ] || grep -q '^A' $$.status; then
  103. quit=0
  104. until [ $quit -ne 0 ]; do
  105. echo_msg "Commit Message:"
  106. if [ -s $logfile ]; then
  107. cat $logfile
  108. commit=",${COLOR_MESSAGE}c${COLOR_NORMAL}:commit"
  109. else
  110. echo_warning "\tEmpty Log File!"
  111. commit=
  112. fi
  113. echo -en "\n${COLOR_MESSAGE}Is the message ok?${COLOR_NORMAL}"
  114. 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} "
  115. read in
  116. case "$in" in
  117. c*) if [ -n "$commit" ]; then
  118. $SVN commit $locations --file $logfile && rm "$logfile" ; quit=1
  119. fi ;;
  120. d*) less $$.diff ;;
  121. s*) cat $$.status ;;
  122. e*) ${EDITOR:-vi} $logfile ;;
  123. q*) quit=1 ;;
  124. *) echo "Excuse me?"
  125. esac
  126. done
  127. else
  128. echo_warning "No changes detected at:$locations"
  129. fi
  130. rm -f $$.status $$.diff
  131. [ "$logfile" != "$$.log" ] || rm -f "$logfile"
  132. }
  133. if [ "$module" == "commit" ]; then
  134. if [ $# -gt 0 ]; then
  135. commit_main "$@"
  136. else
  137. commit_usage
  138. exit 1
  139. fi
  140. fi