Getting the last revision number in SVN?

2019-01-04 07:33发布

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.

标签: svn
25条回答
Emotional °昔
2楼-- · 2019-01-04 08:24

The simplest and clean way to do that (actually svn 1.9, released 2015) is using:

svn info --show-item revision [--no-newline] [SVNURL/SVNPATH] 

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, instructs svn 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

查看更多
闹够了就滚
3楼-- · 2019-01-04 08:25

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 where BASE_URL is the root URL for all paths on the subversion server.

查看更多
Luminary・发光体
4楼-- · 2019-01-04 08:26

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 the svnlook 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 type svnlook help for details. You probably want to use the svnlook youngest command. Note that it requires direct access to the repo directory, so it must be used on the server.

查看更多
来,给爷笑一个
5楼-- · 2019-01-04 08:27

If you want really short one:

svn info ^/

The caret notation is a shorthand for "the URL of the repository's root directory".

查看更多
神经病院院长
6楼-- · 2019-01-04 08:31

Just svn info in BASH will give you all details

RESULT:
Path: .
URL: 
Repository Root: 
Repository UUID: 
Revision: 54
Node Kind: directory
Schedule: normal
Last Changed Author: 
Last Changed Rev: 54
Last Changed Date: 

You will get the REVISION from this

查看更多
手持菜刀,她持情操
7楼-- · 2019-01-04 08:32

If you want to analyse a local working copy, the best tool is svnversion, which comes with Subversion and produces output like 968:1000M. The documentation says:

The version number will be a single number if the working copy is single revision, unmodified, not switched and with an URL that matches the TRAIL_URL argument. If the working copy is unusual the version number will be more complex:

4123:4168     mixed revision working copy
4168M         modified working copy
4123S         switched working copy
4123:4168MS   mixed revision, modified, switched working copy
查看更多
登录 后发表回答