user192164
user192164

Reputation:

SVN revision number as on Stackoverflow site (right bottom)

How do I get my SVN revision number to appear on my website each time I commit?

Upvotes: 2

Views: 495

Answers (5)

Vladimir
Vladimir

Reputation: 6871

Assuming Java and Ant, you can use a task to query the repository and store the infos into some Ant properties. This could be handy to get not only the revision number but also the tag/branch name.

You can see a sample task in my sandbox

Upvotes: 0

duffymo
duffymo

Reputation: 309008

Looks like they embed it in the page ("view source" on this page):

<div id="svnrev">svn revision: 4999</div> 

I can get it using Tortoise on Windows by looking at the log for a repository. You don't say what OS you're using or if it's command shell access for you.

Check the SVN Red Bean book for the command you need.

Upvotes: 3

timdev
timdev

Reputation: 62914

Assuming PHP here, but you could easily do this in any server-side language.

<?PHP
$revString = '$Revision$'; // Subversion will substitute something like $Revision: <number> $
$revNum = magic($revString); // magic parses the integer number out of the string.
echo "Subversion revision: $revNum";

Upvotes: 0

Alex Martelli
Alex Martelli

Reputation: 882681

You must have something like $Revision$ in the file whose revision you want to track (say foo.html), and tell Svn to track and substitute that keyword in the file, i.e.:

svn propset svn:keywords "Revision" foo.html

Svn will then, when the file's changed, change that expression into $Revision: 23 or whatever the revision number may be. (You can do that in other files too, of course, but then -- depending how you compose your site -- you'll have to get the info from each file of interest and add it to the page you're displaying, e.g. via templating or whatever).

Upvotes: 3

Bostone
Bostone

Reputation: 37154

Basically you will need to execute svn info on command line and then parse the output (so given this happens on the server). See this blog entry for example

The output from svn info looks like this:

Path: .
URL: http://continuum.td.foo.com/svn/EngTools/Atom/trunk/aimv-test-daemon
Repository Root: http://continuum.td.foo.com/svn
Repository UUID: 69079f5b-ed1a-0410-902f-f9949c1bbd36
Revision: 107090
Node Kind: directory
Schedule: normal
Last Changed Author: johndoe
Last Changed Rev: 107006
Last Changed Date: 2009-07-09 15:21:17 -0700 (Thu, 09 Jul 2009)

Say you don't want to run daemon or exec you can simply dump the content to some known file after you update your build svn info > svnbuild.info and parse that

Upvotes: 2

Related Questions