Patrick
Patrick

Reputation: 949

PHP how to get revision number file in SVN

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!

Upvotes: 1

Views: 1192

Answers (3)

Chris
Chris

Reputation: 10435

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

Upvotes: 1

sarp
sarp

Reputation: 3750

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

Upvotes: 1

Macmade
Macmade

Reputation: 53930

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

Upvotes: 0

Related Questions