0

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.

hakre
  • 193,403
  • 52
  • 435
  • 836
Dora
  • 292
  • 3
  • 15
  • 1
    This doesn't really have one single thing to do with Javascript, does it? – Pointy Aug 05 '10 at 12:32
  • Your second example works fine here (i prefer `| awk '/Revision:/{print $2}'`, but that's a personal choice), if it doesn't work it's most likely a file-permission problem. – Wrikken Aug 05 '10 at 13:04
  • I added JavaScript so that if a solution is available in javascript i can use it. And the whole scenario appeared because of javascript cache problem. Second example was not giving any result as in my case. Thanks anyway for your remarks – Dora Aug 05 '10 at 13:37

1 Answers1

0

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
  • 752
  • 1
  • 6
  • 17
  • 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 Aug 05 '10 at 13:07
  • 1
    Also, currently line a 4 (index 3) holds the _current_ revision. Line 11 (idx 10) would be the 'last changed revision'.... – Wrikken Aug 05 '10 at 13:12
  • @Wrikken : You are correct, regarding the index of revision number. – Dora Aug 05 '10 at 13:34
  • Well, I'm also correct regarding the format of the `entries` file having changed over time and any manual parsing being unreliable :P – Wrikken Aug 05 '10 at 13:47