dpcj32769 2012-07-27 05:56
浏览 388
已采纳

在PHP中可移植地检索Subversion 1.7版本?

In Subversion 1.6, there was an .svn directory in every working copy directory. I could use the following code to quickly retrive the current revision number without the need for shell access/execution.

public function getSubversionRevision() {
    if(file_exists("../.svn/entries")) {
        $svn = File("../.svn/entries");
        return (int)$svn[3];
    }
    return false;
}

Subversion 1.7 breaks this code. There is now only one .svn directory per local repository. There is an entries file in this directory but it no longer has anything useful for me. It looks like everything I need is now in a SQLite database. Specifically wc.db. I suppose I could use PHP's SQLite functions to get the info I need, but this sounds a little too expensive to run on every (or close to every) page load.

Any ideas? Breaking out the exec function and hoping that Subversion binaries are installed (and in the $PATH!) is a last resort. To summarize, I need to find a way to locate the .svn directory at the root of the repository (which could be different depending on your checkout location) and then somehow parse a file in there (probably wc.db) in a cost-effective way.

  • 写回答

5条回答 默认 最新

  • doqpm82240 2012-07-27 08:42
    关注

    You can write a script to svn update for you every time, and scrap the revision number from the update's output into a file. The following bash script should more or less do it:

    #!/bin/bash
    
    svn --non-interactive update .. 
    svn --non-interactive update .. | perl -p -e "s/.* revision ([\d]*)\./\$1/" > ../version.phtml;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?