tags:

views:

47

answers:

2

Hello,

I need svn revision number from PHP script. I have used the following commands with exec(). But it does not return any thing.

$value = exec("usr/bin/svn --username myusername--password mypassword info /home/mysite/mysite_www/mysite |grep Revision: |cut -c11-", $output, $status); 

or

$value = exec("svn info |grep Revision: |cut -c11-", $output, $status);

I have also tried using share script but no result. Please guide me how to get a SVN revision number using PHP and the command.

+1  A: 

This question has some good answers on the topic:

http://stackoverflow.com/questions/111436/how-can-i-get-the-svn-revision-number-in-php

Falle1234
A: 

I would recommend getting the SVN revision number from the .svn/entries file using something like the following code snippet.

// open .svn/entries file
$content = file_get_contents("/path/to/your/site/.svn/entries");

// get revision number
$lines = explode("\n", $content, 12);
$revision = intval($lines[10]);

// print out the revision number
echo "Revision: " . $revision;

Using this, you could also get the date by parsing the content of $lines[11]

eriktm
Thanxs a lot this solution worked
Dora
Relying on .svn internals (as in: the entries file) should be considered dangerous: svn may update it's format, and at that moment svn still works like a charm but your code breaks. For instance, in svn 1.1 it used to be XML in there...
Wrikken
Also, currently line a 4 (index 3) holds the _current_ revision. Line 11 (idx 10) would be the 'last changed revision'....
Wrikken
@Wrikken : You are correct, regarding the index of revision number.
Dora
Well, I'm also correct regarding the format of the `entries` file having changed over time and any manual parsing being unreliable :P
Wrikken