Using PHP, Perl, or Python (preferably PHP), I need a way to query an SVN database and find out the last revision number sent to SVN. I don't need anything other than that. It needs to be non-intensive (so I do it every 5 minutes as a cron job; SVN's performance should not be affected).
SVN is located on my Intranet, but not my specific computer.
I have SVN installed, but no bindings installed for PHP/Perl/Python. I'm running Windows XP, but I would prefer a platform-independent solution that can also work in Linux. If you have a Linux-only (or XP-only) solution, that would also be helpful.
A note about getting the latest revision number:
Say I've
cd
-ed in a revisioned subdirectory (MyProjectDir
). Then, if I callsvnversion
:... I get "
323:340
", which I guess means: "you've got items here, ranging from revision 323 to 340".Then, if I call
svn info
:... I get "
323
" as revision - which is actually the lowest revision of those that reported bysvnversion
!We can then use
svn info
in recursive mode to get more information from the local directory:... (remove the
grep
to see the more details).Finally, what to do when we want to check what is the latest revision of the online repository (in this case, @
server.com
)? Then we again issuesvn info
, but with-r HEAD
(note the difference between capital-R
option previously, and lowercase-r
now):The interesting thing is -
svn info
still refers to the current subdirectory (MyProjectDir
), however, the online path is reported asMyProjectDir
(as opposed to.
for the local case) - and the online revision reported is the highest (340
- as opposed to the lowest one,323
reported locally).If you have the misfortune of needing to do this from a Windows batch file, here is the incantation you are looking for:
This runs "svn info", iterating through each line of generated output. It uses a colon as a delimiter between the first and second token on the line. When the first token is "Revision" it sets the environment variable REV to the second token.
Looks like there is an entry in the official FAQ for this. The source code is in C but the same principle applies, as outlined here in this mailing list post.
Or
Or
You can get the output in XML like so:
If there is an error then the output will be directed to stderr. To capture stderr in your output use thusly:
This should work in Bash, from a working directory. I've used it in Windows with unixutils installed: