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.
The simplest and clean way to do that (actually svn 1.9, released 2015) is using:
The output is the number of the last revision (joungest) for the SVNURL, or the number of the current revision of the working copy of SVNPATH. The
--no-newline
is optional, instructssvn
not to emit a cosmetic newline (\n
) after the value, if you need minimal output (only the revision number).See: https://subversion.apache.org/docs/release-notes/1.9.html#svn-info-item
The posted solutions don't handle the case when externals are being used.
If I have a URL or a working copy with the
svn:externals
property set, the externals may change and thus the subversion server's latest revision will change. But the latest revision of the working copy or URL will only report the revision number when the svn:externals propty was change or any item lower in the URL path, which is expected behavior.So you either get the
svn:externals
property and iterate over the URLs and pick the heights revision or query the base URL from the subversion server. The version reported from the base URL will contain the latest revision for EVERYTHING on the server.So, if you are using externals, it's best to use
svn info BASE_URL
whereBASE_URL
is the root URL for all paths on the subversion server.Someone else beat me to posting the answer about
svnversion
, which is definitely the best solution if you have a working copy (IIRC, it doesn't work with URLs). I'll add this: if you're on the server hosting SVN, the best way is to use thesvnlook
command. This is the command you use when writing a hook script to inspect the repository (and even the current transaction, in the case of pre-commit hooks). You can typesvnlook help
for details. You probably want to use thesvnlook youngest
command. Note that it requires direct access to the repo directory, so it must be used on the server.If you want really short one:
The caret notation is a shorthand for "the URL of the repository's root directory".
Just
svn info
in BASH will give you all detailsYou will get the REVISION from this
If you want to analyse a local working copy, the best tool is
svnversion
, which comes with Subversion and produces output like968:1000M
. The documentation says: