Automatically get the SVN Revision Number of your Project

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 and located in http://svnserver/ 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/ and http://svnserver/ 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.

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];
        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.

Jundy Cosmod Site

3 0
Viewed: 12 976 times
Version: all
Category: Tutorials
Written by: jcagentzero
Last updated by: jcagentzero
Created on: Apr 10, 2014
Last updated: 10 years ago
Update Article


View all history