Is there a Subversion command to show the current revision number?
After svn checkout
I want to start a Python script and need the revision number in a variable. It would be great if there is a command like svn info get_revision_number
.
Is there a Subversion command to show the current revision number?
After svn checkout
I want to start a Python script and need the revision number in a variable. It would be great if there is a command like svn info get_revision_number
.
svn info
, I believe, is what you want.
If you just wanted the revision, maybe you could do something like:
svn info | grep "Revision:"
There is also a more convenient (for some) svnversion
command.
Output might be a single revision number or something like this (from -h):
4123:4168 mixed revision working copy
4168M modified working copy
4123S switched working copy
4123:4168MS mixed revision, modified, switched working copy
First of all svn status has the revision number, you can read it from there.
Also, each file that you store in SVN can store the revision number in itself -- add the $Rev$
keyword to your file and run propset: svn propset svn:keywords "Revision" file
Finally, the revision number is also in .svn/entries
file, fourth line
Now each time you checkout that file, it will have the revision in itself.
You can use os.system()
to execute a command line like this:
svn info | grep "Revision" | awk '{print $2}'
I do that in my nightly build scripts.
Also on some platforms there is a svnversion
command, but I think I had a reason not to use it. Ahh, right. You can't get the revision number from a remote repository to compare it to the local one using svnversion.
I think I have to do svn info and then retrieve the number with a string manipulation from "Revision: xxxxxx" It would be just nice, if there were a command that returns just the number :)
thanks!
is there also a command just to check which revision number is on the svn server WITHOUT making a checkout?
Use something like the following, taking advantage of the XML output of subversion:
# parse rev from popen "svn info --xml"
dom = xml.dom.minidom.parse(os.popen('svn info --xml'))
entry = dom.getElementsByTagName('entry')[0]
revision = entry.getAttribute('revision')
Note also that, depending on what you need this for, the <commit revision=...>
entry may be more what you're looking for. That gives the "Last Changed Rev", which won't change until the code in the current tree actually changes, as opposed to "Revision" (what the above gives) which will change any time anything in the repository changes (even branches) and you do an "svn up", which is not the same thing, nor often as useful.