tags:

views:

94

answers:

3

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!

A: 

Use the svn_blame() function to get informations, including the revision number, about the file in your SVN repository.

Macmade
+1  A: 
function get_revision($filename) {
    $status = @shell_exec('svnversion '.realpath($filename));
    if ( preg_match('/\d+/', $status, $match) ) {
       return $match[0];
    }else {
       return false;
    }
}
celalo
+1  A: 

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).

Chris Smith
This is assuming that you want to get the information from a checkout, rather than from the repository itself.
Chris Smith