#!/usr/bin/env ruby require 'logger' require 'rexml/document' require 'svn/repos' require 'svn/core' require 'iconv' # --- initialize the logger HOOK_HOME = File.dirname(__FILE__) LOGGER = Logger.new("#{HOOK_HOME}/svn.log") LOGGER.level = Logger::DEBUG LOGGER.debug( "#{__FILE__}##{__LINE__}: start with params #{$*}") # --- open configuration file CMD_NAME = File.basename(__FILE__, ".rb") doc = REXML::Document.new File.new( File.join( HOOK_HOME, "#{CMD_NAME}.xml")) phpPath = doc.elements['conf/php-path/text()'].to_s() mantisPath = doc.elements['conf/mantis-path/text()'].to_s() LOGGER.debug( "#{__FILE__}##{__LINE__}: config php=#{phpPath} mantis=#{mantisPath}") # --- get commit log with the ruby api binding. # Don"t use svnlook log command that have bad encoding throught httpd Apache # http://svn.haxx.se/dev/archive-2004-09/0996.shtml repos = Svn::Repos.open("#{ARGV[0]}") commit_log = repos.prop(Svn::Core::PROP_REVISION_LOG, Integer(ARGV[1])) LOGGER.debug( "#{__FILE__}##{__LINE__}: UNICODE result=#{commit_log}") # --- convert Unicode to latin1 because mantis is not UTF-8 compliant # http://www.mantisbt.org/bugs/view.php?id=8733 c = Iconv.new('UTF-8', 'ISO-8859-1') commit_log = c.iconv(commit_log) LOGGER.debug( "#{__FILE__}##{__LINE__}: length=#{commit_log.strip.size()} result=#{commit_log}") # --- submit the commit to mantis command = "#{File.join( phpPath, 'php')} #{File.join( mantisPath, 'core/checkin.php')} <<< \"#{commit_log}\"" result = `#{command}` LOGGER.debug( "#{__FILE__}##{__LINE__}: exit=(#{$?}) result=#{result}") exit!(0)