How can you automatically import the latest build/revision number in subversion?
The goal would be to have that number visible on your webpage footer like SO does.
To find information about the history of a file or directory, use the svn log command. svn log will provide you with a record of who made changes to a file or directory, at what revision it changed, the time and date of that revision, and, if it was provided, the log message that accompanied the commit.
As you saw in the section called “Revisions”, revision numbers in Subversion are pretty straightforward—integers that keep getting larger as you commit more changes to your versioned data. Still, it doesn't take long before you can no longer remember exactly what happened in each and every revision.
Have your build process call the svnversion command, and embed its output into generated {source|binaries}. This will not only give the current revision (as many other examples here do), but its output string will also tell whether a build is being done in a mixed tree or a tree which doesn't exactly match the revision number in question (ie. a tree with local changes).
With a standard tree:
$ svnversion 3846
With a modified tree:
$ echo 'foo' >> project-ext.dtd $ svnversion 3846M
With a mixed-revision, modified tree:
$ (cd doc; svn up >/dev/null 2>/dev/null) $ svnversion 3846:4182M
The svnversion
command is the correct way to do this. It outputs the revision number your entire working copy is at, or a range of revisions if your working copy is mixed (e.g. some directories are up to date and some aren't). It will also indicate if the working copy has local modifications. For example, in a rather unclean working directory:
$ svnversion 662:738M
The $Revision$ keyword doesn't do what you want: it only changes when the containing file does. The Subversion book gives more detail. The "svn info" command also doesn't do what you want, as it only tells you the state of your current directory, ignoring the state of any subdirectories. In the same working tree as the previous example, I had some subdirectories which were newer than the directory I was in, but "svn info" doesn't notice:
$ svn info ... snip ... Revision: 662
It's easy to incorporate svnversion into your build process, so that each build gets the revision number in some runtime-accessible form. For a Java project, for example, I had our makefile dump the svnversion output into a .properties file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With