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条回答
干净又极端
2楼-- · 2019-01-04 08:17

$ svn log | head -10 on whatever directory that has a .svn folder

查看更多
成全新的幸福
3楼-- · 2019-01-04 08:19

The following should work:

svnlook youngest <repo-path>

It returns a single revision number.

查看更多
太酷不给撩
4楼-- · 2019-01-04 08:20
  • Starting with Subversion 1.9 you can use option --show-item to get a value of one of fields of svn info command's output. This command will display revision number only:

    svn info --show-item=revision <URL-to-repository>
    
  • Get XMLed output of svn info using --xml option and use PowerShell to get the revision number. Here is a simple example:

    [xml]$svninfo = svn info <REPOSITORY-URL> --xml -r HEAD
    $latestrevnum = $svninfo.info.entry.revision
    $latestrevnum
    
  • Using VisualSVN Server 3.4 or newer, you can get the number of revisions in a repository by running these commands:

    $repo = Get-SvnRepository <REPOSITORY-NAME>

    $repo.Revisions

    See Get-SvnRepository PowerShell cmdlet reference for more information.

查看更多
小情绪 Triste *
5楼-- · 2019-01-04 08:22

Update: Subversion 1.9 will support a new command "svn youngest" that outputs only the latest revision number. The difference to "svnlook youngest" is that "svn youngest" also works remotely.

http://subversion.tigris.org/issues/show_bug.cgi?id=4299

查看更多
家丑人穷心不美
6楼-- · 2019-01-04 08:24

You can try the below command:

svn info -r 'HEAD' | grep Revision: | awk -F' ' '{print $2}'
查看更多
成全新的幸福
7楼-- · 2019-01-04 08:24

This will get just the revision number of the last changed revision:

<?php
$REV="";
$repo = ""; #url or directory
$REV = svn info $repo --show-item last-changed-revision;
?>

I hope this helps.

查看更多
登录 后发表回答