SVN version number as on Stackoverflow site (bottom right)

How do I get my SVN version number to display on my site every time I commit?

+2


source to share


5 answers


You should have something like $Revision$

in the file whose version you want to track (say foo.html

) and tell Svn to track and replace that keyword in the file, i.e.

svn propset svn:keywords "Revision" foo.html

      



Svn will be when the file changes, change this expression to $Revision: 23

or whatever version number. (You can of course do this in other files as well, but then - depending on how you create your site - you will need to get information from each file of interest and add it to the page you display, for example through templates or what something else).

+3


source


It looks like they are embedding it in the page (the "view source" on that page):

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

      



I can get it using Tortoise on Windows by looking at the log for the repository. You don't say which OS you are using, or if it manages the shell for you.

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

+3


source


Basically you need to execute svn info

on the command line and then parse the output (so this happens on the server). See the blog post for example

The result 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)

      

Suppose you don't want to start a daemon or exec, you can just dump the contents of some known file after updating the assembly svn info > svnbuild.info

and analyze that

+2


source


Assuming PHP is here, but you can easily do it 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";

      

0


source


Assuming Java and Ant, you can use a task to query the repository and save information to some Ant properties. It can be useful to get not only the revision number but also the tag / branch name.

You can see an example of a task in my sandbox

0


source







All Articles