When SVN commits the code, it automatically updates the changed files and directories to the Web directory:
1. According to the update SVN log, automatically in the/data/svn-update/mmoyu/directory update changed branch directory
2. According to update SVN log, copy new files (or changed files) from/data/svn-update/mmoyu/ Branch directory or delete files (or folders) in target directory
Ps:
Mmoyu is one of my svn repositories,
51open is one of the branches,
Log generated in the/DATA/WWW/LOGS/SVN directory
#!/usr/local/php/bin/php<?php/** * svn hook post-commit written by php * @author : yearnfar * @website : http://51open.net */ Define (' Svnbin_path ', '/usr/local/svn/bin ');d efine (' Svnlog_path ', '/data/www/logs/svn '); //$ Svnpath[lable] = array (Svndir, updatedir, dstdir); $svnpath ["51open"] = array (" 51open ", "/data/svn-update/mmoyu/51open ", "/data/www/mmoyu/51open "); function main () { global $argc, $argv, $svnpath;if ($argc < 3) exit ("params error!"); List (, $path, $no) = $argv; $logs = array (); $info = array (); if (Popen_svnlook (' info ', $no, $path, $info) ===-1) {exit ("look info Error! ");} else {list ($author, $time, $version, $message) = $info; $logs [] = "author: {$author}time: {$time}version: {$version}message: {$message} ";} $logs [] = "change files:"; $changefiles = array ();if (Popen_svnlook (' Changed ', $no, $path, $changefiles) ===-1) {exit ("look changed error!");} else {$logs [] = implode (', $changefiles);} $logs [] = "change dirs:"; $changedirs = array ();if (Popen_svnlook (' Dirs-changed ', $no, $path, $changedirs) ===-1) {exit ("look dirs-changed error!");} else {$logs [] = implode (', $changedirs);} $sub = ";foreach ($changedirs as $dir) {//if ($sub = =") { foreach ($svnpath as $k => $v) {if (strlen ($dir) >strlen ($v [0]) && substr ($dir, 0, strlen ($v [0]) = = $v [0]) {$sub = $k; $offset = strlen ($v [0]); if ($sub = = ") return ;//if (POPEN_SVN (' Update ', $no, $svnpath [$sub][1] . substr ($dir, $ Offset)) ===-1) {exit ("update error!");}} foreach ($changefiles as $line) {$op = $line [0]; $line = substr (Trim ( substr ($line, 1)), $offset); $src = $svnpath [$sub][1] . $line; $dst = $svnpath [$sub][2] . $line; if ($op = = ' D ') {system_withlog ("rm -rf {$DST} ", $logs); continue;} elseif ($op = = ' A ') {if (!is_dir (dirname ($DST))) {system_withlog ("mkdir -p " . DirName ($DST), $logs);}} if (Is_file ($SRC)) {system_withlog ("cp -f {$src} {$dst}", $logs);}} $logs [] = "\r\n\r\n"; $logfile = svnlog_path. " /{$sub}_{$no}.log "; $fp = fopen ($logfile, " WB ") fwrite ($fp, implode (" \ r \ n ", $ Logs) fclose ($fp); echo "All files updaTed! logs: {logfile} "; return ;} function popen_svnlook ($cmd, $no, $path, & $ret = array ()) {$ph = popen (Svnbin_path. " /svnlook {$cmd} -r {$no} {$path} ", ' R '); while (($buffer = fgets ( $PH, 1024))!==false) {$ret [] = $buffer;} $errno = feof ($ph) ? 0 : -1;pclose ($ph); return $errno;} &NBSP;FUNCTION&NBSP;POPEN_SVN ($cmd, $no, $path) {$ph = popen (svnbin_path. ") /svn {$cmd} -r {$no} $path ", ' R '); $ret = $ph ? 0: -1;pclose ( $PH);return $ret;} function system_withlog ($cmd, & $logs =array ()) {System ($CMD); $logs [] = $cmd;} //run~main ();
SVN post-commit written in PHP