1

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!

3 Answers 3

1
function get_revision($filename) {
    $status = @shell_exec('svnversion '.realpath($filename));
    if ( preg_match('/\d+/', $status, $match) ) {
       return $match[0];
    }else {
       return false;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.