PHP Operation SVN version server class Code _php tutorial

Source: Internet
Author: User
svnpeer.php
Copy CodeThe code is as follows:
/**
*
* This class for execute the external program of SVN
*
* @auth Seven Yang
*
*/
Class Svnpeer
{
/**
* List directory entries in the repository
*
* @param string a specific project repository path
* @return bool True, if validated successfully, otherwise false
*/
static public Function ls ($repository)
{
$command = "SVN ls". $repository;
$output = Svnpeer::runcmd ($command);
$output = Implode ("
", $output);
if (Strpos ($output, ' non-existent in that revision ')) {
return false;
}
Return "
" . $command. "
" . $output;
}
/**
* Duplicate something in working copy or repository, remembering history
*
* @param $src
* @param $DST
* @param $comment string Specify log message
* @return bool True, if copy successfully, otherwise return the error message
*
* @todo comment need addslashes for SVN commit
*/
static public function copy ($SRC, $DST, $comment)
{
$command = "SVN cp $src $DST-m ' $comment '";
$output = Svnpeer::runcmd ($command);
$output = Implode ("
", $output);
if (Strpos ($output, ' Committed Revision ')) {
return true;
}
Return "
" . $command. "
" . $output;
}
/**
* Remove files and directories from version control
*
* @param $url
* @return bool True, if delete successfully, otherwise return the error message
*
* @todo comment need addslashes for SVN commit
*/
static public Function Delete ($url, $comment)
{
$command = "svn del $url-M ' $comment '";
$output = Svnpeer::runcmd ($command);
$output = Implode ('
', $output);
if (Strpos ($output, ' Committed Revision ')) {
return true;
}
Return "
" . $command. "
" . $output;
}
/**
* Move and/or rename something in working copy or repository
*
* @param $src String Trunk path
* @param $dst string New branch Path
* @param $comment string Specify log message
* @return bool True, if move successfully, otherwise return the error message
*
* @todo comment need addslashes for SVN commit
*/
static public function Move ($SRC, $DST, $comment)
{
$command = "SVN mv $src $dst-M ' $comment '";
$output = Svnpeer::runcmd ($command);
$output = Implode ('
', $output);
if (Strpos ($output, ' Committed Revision ')) {
return true;
}
Return "
" . $command. "
" . $output;
}
/**
* Create A new directory under version control
*
* @param $url string
* @param $comment string The SVN message
* @return bool True, if create successfully, otherwise return the error message
*
* @todo comment need addslashes for SVN commit
*/
static public function mkdir ($url, $comment)
{
$command = "svn mkdir $url-M ' $comment '";
$output = Svnpeer::runcmd ($command);
$output = Implode ('
', $output);
if (Strpos ($output, ' Committed Revision ')) {
return true;
}
Return "
" . $command. "
" . $output;
}
static Public function diff ($pathA, $pathB)
{
$output = Svnpeer::runcmd ("svn diff $pathA $pathB");
Return implode ('
', $output);
}
static public Function Checkout ($url, $dir)
{
$command = "CD $dir && SVN co $url";
$output = Svnpeer::runcmd ($command);
$output = Implode ('
', $output);
if (Strstr ($output, ' Checked out Revision ')) {
return true;
}
Return "
" . $command. "
" . $output;
}
static public Function Update ($PATH)
{
$command = "CD $path && svn up";
$output = Svnpeer::runcmd ($command);
$output = Implode ('
', $output);
Preg_match_all ("/[0-9]+/", $output, $ret);
if (! $ret [0][0]) {
Return "
" . $command. "
" . $output;
}
return $ret [0][0];
}
static public Function merge ($revision, $url, $dir)
{
$command = "CD $dir && svn merge-r1: $revision $url";
$output = Implode ('
', Svnpeer::runcmd ($command));
if (Strstr ($output, ' Text conflicts ')) {
Return ' Command: '. $command. '
'. $output;
}
return true;
}
static public Function commit ($dir, $comment)
{
$command = "CD $dir && svn commit-m ' $comment '";
$output = Implode ('
', Svnpeer::runcmd ($command));
if (Strpos ($output, ' Committed revision ') | | empty ($output)) {
return true;
}
return $output;
}
static public Function GetStatus ($dir)
{
$command = "CD $dir && svn st";
Return Svnpeer::runcmd ($command);
}
static public Function hasconflict ($dir)
{
$output = Svnpeer::getstatus ($dir);
foreach ($output as $line) {
if (' C ' = = substr (Trim ($line), 0, 1) | | ('! ' = = substr (Trim ($line), 0, 1))) {
return true;
}
}
return false;
}
/**
* Show the log messages for a set of path with XML
*
* @param path string
* @return Log message string
*/
static public Function GetLog ($path)
{
$command = "SVN log $path--xml";
$output = Svnpeer::runcmd ($command);
Return implode (", $output);
}
static public Function getpathrevision ($path)
{
$command = "SVN info $path--xml";
$output = Svnpeer::runcmd ($command);
$string = Implode (' ', $output);
$xml = new SimpleXMLElement ($string);
foreach ($xml->entry[0]->attributes () as $key = = $value) {
if (' revision ' = = $key) {
return $value;
}
}
}
static public Function getheadrevision ($path)
{
$command = "CD $path && svn up";
$output = Svnpeer::runcmd ($command);
$output = Implode ('
', $output);
Preg_match_all ("/[0-9]+/", $output, $ret);
if (! $ret [0][0]) {
Return "
" . $command. "
" . $output;
}
return $ret [0][0];
}
/**
* Run a cmd and return result
*
* @param string command line
* @param boolen True need add the SVN authentication
* @return Array The contents of the output that SVN execute
*/
Static protected function Runcmd ($command)
{
$authCommand = '--username '. Svn_username. '--password '. Svn_password. '--no-auth-cache--non-interactive--config-dir '. Svn_config_dir. '. Subversion ';
EXEC ($command. $authCommand. "2>&1", $output);
return $output;
}
}

http://www.bkjia.com/PHPjc/324524.html www.bkjia.com true http://www.bkjia.com/PHPjc/324524.html techarticle svnpeer.php Copy Code code as follows:? PHP/** * * This class for execute the external program of SVN * * @auth Seven Yang Qineer@gma il.com * * */class Svnpeer {/** * List Director ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.