#!/usr/bin/php
<?php
// written by aclight to work with subversion
function svnhook_postcommit($argc, $argv) {
  $repos = $argv[1];  // repository path
  // NOTE:  When called by the subversion hook, the $repos argument will NOT 
  // have a trailing slash (eg. /usr/local/subversion/projects_svn)
  $rev = $argv[2];    // revision number
  $block_db_update = $argv[3];    // set to 1 to prevent database updates (for debugging purposes)
  
  $svnlook_path='/usr/bin/svnlook';

  $fd = fopen('error_log', "w");

  $author_command = sprintf("%s author -r %s %s", $svnlook_path, $rev, $repos);
  $author_command = escapeshellcmd($author_command);
  $author=trim(shell_exec($author_command));
  
  $changed_command = sprintf('%s -r %s changed %s', $svnlook_path, $rev, $repos);
  $changed_command = escapeshellcmd($changed_command);
  $changed = shell_exec($changed_command);
  $changed = trim($changed); 
  $changed = explode("\n", $changed);
 
  $message_command = sprintf("%s -r %s log %s", $svnlook_path, $rev, $repos);
  $message_command = escapeshellcmd($message_command);
  $message = trim(shell_exec($message_command));

  $args = array();
  $args[0] = $argv[0];
  $args[1] = '/var/www/example.com/public/sites/all/modules/cvslog/xcvs/xcvs-config.php';
  $args[2] = $author;
  $args[3] = $repos;
  $args[4] = $changed;
  $args[5] = $rev;
  $args[6] = $message;
  $args[7] = $block_db_update;
  $argc = count($args);
  $argv = $args;
  include_once('/var/www/example.com/public/sites/all/modules/cvslog/xcvs/xsvn-utility.php');
  $changes = array();
  xsvn_process_files($argv[4], $changes);
  $argv[4] = $changes;
  include_once('/var/www/example.com/public/sites/all/modules/cvslog/xcvs/xcvs-loginfo.php');  
  xcvs_init($argc, $argv);
  fclose($fd);  
  exit(0);
}

svnhook_postcommit($argc, $argv);
?>
