Re: Getting info from SVN commit with php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank You for that fast reply.

PECL was something that I din't know about. But I'll dig in with Your examples and also PECL and try to find most simple but well-working solution.
Also sorry for Return Receipt, turned that off.


mike wrote:
On 7/23/08, Raido <raido.aasoja@xxxxxxxxx> wrote:

I have an SVN server but I need to add some extra to commit message which
PHP will get  and use(for example use the parameters from commit message to
change data on mysql database... (if commit messages first line has
character *, then run sql query... "update tasks set some_row='OK'
where...."

There's an SVN PECL module: http://pecl.php.net/package/svn

Also, you can easily run these kind of commands via system() - I've
done that in the past, but now that there's this SVN PECL module I've
been wanting to get aligned that way. Always better in my opinion to
use APIs and not system() calls.

If the svn module doesn't meet your needs you can ask for
enhancements, or just use system() for now.

here's a couple functions I wrote.
$config['svn'] was the path to the svn command (like /usr/bin/svn)

i used the xml output option so i could parse it using simplexml.
also, i pass it a username, password and repository since i support
multiple repositories and each one has a unique username/password set.
it worked like a charm. i am sure you can tailor this code to suit
your needs.

# get the latest revision #
function svn_latest($username, $password, $repository) {
        $xml = simplexml_load_string(shell_exec($GLOBALS['config']['svn']."
info --xml --non-interactive --no-auth-cache --username {$username}
--password{$password} svn://localhost/{$repository}"));
        return intval($xml->entry->commit['revision']);
}

function svn_history($username, $password, $repository, $count = 20,
$start = 0, $latest = 0) {
        # svn's revisions are incremental, so we need to calculate
backwards to find the right offsets
        if($latest == 0) {
                $latest = svn_latest($username, $password, $repository);
        }
        $start = $latest - $start;
        $end = intval($start - $count) + 1;
        if($end < 0) { $end = 0; }
        $xml = simplexml_load_string(shell_exec($GLOBALS['config']['svn']."
log --xml --non-interactive --no-auth-cache --username {$username}
--password {$password} -r {$start}:{$end}
svn://localhost/{$repository}"));
        return $xml;
}



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux