Edgewall Software

Ticket #897: trac-pre-commit-hook.svn.diff

File trac-pre-commit-hook.svn.diff, 2.1 KB (added by ivanoe, 7 years ago)

svn diff version of pre-commit

  • trac-pre-commit-hook

     
    99# 
    1010# This script should be invoked from the subversion pre-commit hook like this: 
    1111# 
     12# LINUX: 
     13# 
    1214#  REPOS="$1" 
    1315#  TXN="$2" 
    1416#  TRAC_ENV="/somewhere/trac/project/" 
    1517#  LOG=`/usr/bin/svnlook log -t "$TXN" "$REPOS"` 
    1618#  /usr/bin/python /some/path/trac-pre-commit-hook "$TRAC_ENV" "$LOG" || exit 1 
    1719# 
     20# WINDOWS: sample of pre-commit.bat (must use temporary files for the log message) 
     21# 
     22##SET REPOS=%1 
     23##SET TXN=%2 
     24## 
     25##::----------------------------- 
     26##::Call the TRAC pre-commit hook 
     27##:: 
     28##SET TRAC_ENV=C:\somewhere\trac\project 
     29##SET LOG_FILE=%TEMP%.\svnfileT-%TXN% 
     30## 
     31##svnlook log -t %TXN% %REPOS%>%LOG_FILE% 
     32## 
     33##python [trac-path]\contrib\trac-pre-commit-hook "%TRAC_ENV%" "file:%LOG_FILE%" 
     34##IF ERRORLEVEL 1 SET TRAC_CANCEL=YES 
     35##DEL %LOG_FILE% 
     36##IF DEFINED TRAC_CANCEL GOTO :ERROR 
     37##:: 
     38##::----------------------------- 
     39## 
     40##:SUCCESS 
     41##EXIT 0 
     42## 
     43##:ERROR 
     44##EXIT 1  
     45## 
     46 
    1847import os 
    1948import re 
    2049import sys 
     
    2756 
    2857    env_path = sys.argv[1] 
    2958    log = sys.argv[2] 
     59    log = _readFromFile( log ) 
    3060 
    3161    tickets = [] 
    3262    for tmp in re.findall('(?:closes|fixes|addresses|references|refs|re)' 
     
    5383    else: 
    5484        sys.exit(0) 
    5585 
     86def _readFromFile(message): 
     87    """ Ivan Melnychuk: SOLUTION FOR WINDOWS SYSTEMS: 
     88    Windows does not support returning values from script. 
     89    Therefore temporary files may be used to keep some information like commit message 
     90    If the 'message' starts with 'file:', and the file with indicated name exists, then read the text message from the file rather then using the text directly 
     91    Even though actual message also may start with such prefix, it is very unlikely that the file exists with such a name by accident 
     92    """ 
     93    if message[:5] == 'file:' and os.path.exists( message[5:] ): 
     94        f = open( message[5:], 'r' ) 
     95        message = f.read() 
     96        f.close() 
     97        return message 
     98    return message; 
     99 
    56100if __name__ == '__main__': 
    57101    main() 
    58102