Quantcast
Channel: Live News for Yii Framework
Viewing all articles
Browse latest Browse all 3375

[Wiki] Automatically get the SVN Revision Number of your Project

$
0
0

When you are handling so many projects and those projects are saved in different repository locations, you may find it very difficult to keep track all the versions and revisions manually and it will be much harder if you are developing in multiple repository branches.

For example, you have project named example.com and located in http://svnserver/example.com/trunk. But there are two projects branched out from the same trunk but has different modifications and you are doing the modifications at the same time. You have http://svnserver/example.com/branches/blog.example.com and http://svnserver/example.com/branches/bloggable.example.com. When you update this branches it will give you revision and changed revision. revision is the revision number of the whole repository location, while changed revision is the revision of specific files and folders.

Let us say you have the following changed revisions and you want to display them in your websites for you to know what is the exact revision number to need to checkout when you need to modify or fix bugs. - http://svnserver/example.com/trunk 223r - http://svnserver/example.com/branches/blog.example.com 220r - http://svnserver/example.com/branches/bloggable.example.com 219r

Solution: I created a component where it will get the exact changed revision number, all you need to do is to update/checkout your repository.

class GetChangedRevision {
 
    public function getRevision() {
 
        if (file_exists(dirname(__FILE__) . '/../../.svn/wc.db')) {
 
            $db = new SQLite3(dirname(__FILE__) . '/../../.svn/wc.db');
 
            $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
            if ($result) {
                $row = $result->fetchArray();
                if ($row['changed_revision'] != "") {
                    $row['changed_revision'] = "." . $row['changed_revision'];
                }
            }
            $svnrev = $row['changed_revision'];
        } else if (file_exists(dirname(__FILE__) . '/../../.svn/entries')) {
 
            $svn = File('.svn/entries');
            $svnrev = "." . $svn[10];
            unset($svn);
        }
 
        return $svnrev;
    }
 
}

Then in your view/layout or where ever you want to display the changed revision number. Add the following code.

$svnrev = new GetChangedRevision();
echo "Revision: ".$svnrev->getRevision();

That's it. Hopefully this will be helpful to you guys.


Viewing all articles
Browse latest Browse all 3375

Trending Articles