Skip to content

Instantly share code, notes, and snippets.

@pix0r
Created September 1, 2010 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pix0r/561119 to your computer and use it in GitHub Desktop.
Save pix0r/561119 to your computer and use it in GitHub Desktop.
<?php
define('REPOSITORY_PATH', "/path/to/svn/repo");
// Note: You'll need to set this part up yourself :)
define('NOTIFY_URL', 'http://site.com/notify.php?rev=%rev%&author=%author%&msg=%msg%');
define('PATH_IDEAL_LEN', 30);
define('PATH_MAX_LEN', 50);
$argv = $_SERVER['argv'];
$argc = $_SERVER['argc'];
$repo = $argv[1];
$rev = $argv[2];
if(empty($repo) || empty($rev)) {
die("Error: no repository or revision supplied");
}
$changed_dirs = "svnlook dirs-changed -r $rev " . REPOSITORY_PATH;
exec($changed_dirs, $dir_output);
// Find common changed dirs
$match = false;
foreach ($dir_output as $d) {
if ($match === false) {
$match = $d;
} else {
for ($x = 0; $x < strlen($match); $x++) {
if ($match{$x} != $d{$x}) {
$d = substr($match, 0, $x - 1);
break;
}
}
}
}
echo "Common changed dir: $match\r\n";
// Trim dir if necessary
if (strlen($match) > PATH_IDEAL_LEN) {
$parts = explode('/', $match);
for ($x = 0; $x < count($parts); $x++) {
if ($parts[$x] == 'trunk') {
$match = implode('/', array_slice($parts, 0, $x));
break;
}
if ($parts[$x] == 'branches' && count($parts) > $x + 1) {
$match = implode('/', array_slice($parts, 0, $x + 1));
break;
}
}
echo "Attempted to trim: $match\r\n";
}
if (strlen($match) > PATH_MAX_LEN) {
$match = substr($match, 0, PATH_MAX_LEN) . '...';
}
// Get author and commit message
$cmd = "svnlook info -r $rev " . REPOSITORY_PATH;
exec($cmd, $info_output);
$author = $info_output[0];
$msg = '[' . $match . '] ';
$msg .= implode(' ', array_slice($info_output, 3, count($info_output) - 1));
$search = array('%rev%', '%author%', '%msg%');
$replace = array($rev, urlencode($author), urlencode($msg));
$url = str_replace($search, $replace, NOTIFY_URL);
file_get_contents($url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment