pre-commit 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/sh
  2. REPOS="$1"
  3. TXN="$2"
  4. SVNLOOK=/usr/bin/svnlook
  5. svnl() {
  6. cmd=$1
  7. shift
  8. $SVNLOOK $cmd "$REPOS" -t "$TXN" $*
  9. }
  10. rc=0
  11. # exclude all third-party files from consideration, we don't want to do any
  12. # checks for them
  13. #
  14. # Also don't impose any constraints on commits to previous 2.x branches.
  15. all_changed_files=`svnl changed | \
  16. grep "^[AU]" | \
  17. sed 's/^....//' | \
  18. egrep -v "branches/WX_2_" | \
  19. egrep -v "wxWidgets/vendor" | \
  20. egrep -v "src/(expat|tiff|regex|jpeg|stc/scintilla|zlib)" | \
  21. egrep -v "src/msw/version.rc" | \
  22. egrep -v "_wrap.cpp" | \
  23. egrep -v "wxPython/.*/docs/.*\.html$"`
  24. # analyze the changed files to find all non-binary and all source files
  25. for f in $all_changed_files; do
  26. mimetype=`svnl proplist -v $f |
  27. fgrep "svn:mime-type" |
  28. sed 's/^ svn:mime-type : //'`
  29. case $mimetype in
  30. ''|text/*)
  31. ;;
  32. *)
  33. continue
  34. ;;
  35. esac
  36. changed_text_files="$changed_text_files $f"
  37. case $f in
  38. *.cpp|*.h|*.py)
  39. changed_sources="$changed_sources $f"
  40. ;;
  41. esac
  42. done
  43. for f in $changed_sources; do
  44. if svnl cat $f | fgrep -q ' '; then
  45. echo "Please remove TABs from $f before committing." >&2
  46. rc=1
  47. fi
  48. case $f in
  49. */wx/chartype.h)
  50. # This file defines _T() for compatibility so don't check it.
  51. ;;
  52. */docs/doxygen/overviews/changes_since28.h)
  53. # And this one describes changes from _T() to wxT().
  54. ;;
  55. *)
  56. if svnl cat $f | fgrep -qw '_T'; then
  57. echo "Please use wxT() instead of _T() in $f." >&2
  58. rc=1
  59. fi
  60. ;;
  61. esac
  62. done
  63. for f in $changed_text_files; do
  64. if ! svnl cat $f | iconv -f utf8 -t WCHAR_T > /dev/null; then
  65. echo "File $f doesn't use UTF-8, please convert it before committing." >&2
  66. echo "(or set svn:mime-type property correctly if the file is binary)." >&2
  67. rc=1
  68. fi
  69. done
  70. exit $rc