Say I have a file in a SVN. How do I use PHP to check the file's revision number?
I see the SVN function list at http://www.php.net/manual/en/ref.svn.php but am not sure which one to use or the exact code to do it.
Thanks!
Say I have a file in a SVN. How do I use PHP to check the file's revision number?
I see the SVN function list at http://www.php.net/manual/en/ref.svn.php but am not sure which one to use or the exact code to do it.
Thanks!
Use the svn_blame() function to get informations, including the revision number, about the file in your SVN repository.
function get_revision($filename) {
$status = @shell_exec('svnversion '.realpath($filename));
if ( preg_match('/\d+/', $status, $match) ) {
return $match[0];
}else {
return false;
}
}
You want svn_status
.
Usage would be something like:
$status = svn_status('path/to/file');
$revision = $status[0]['cmt_rev'];
You definitely don't want to be using svn_blame
, as that's a very expensive operation (it has to retrieve a lot of history for the file to figure out who changed what, and that means (slow) requests to the server).