php操作SVN版本服务器类代码_php技巧
SvnPeer.php
/**
*
* 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;
}
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Version control is a very common operation in PHP development, and the most commonly used tool is SVN (Subversion). It can easily manage historical versions of code and code updates during collaborative development. The following will introduce how to use SVN for version control in PHP development. 1. Install the SVN client and server. First, you need to install the SVN client and server. The SVN client can download the corresponding version from the SVN official website and install it, while the server needs to be built by yourself. The specific method can be

Introduction to SVN SVN (Subversion) is a centralized version control system used to manage and maintain code bases. It allows multiple developers to collaborate on code development simultaneously and provides a complete record of historical modifications to the code. By using SVN, developers can: Ensure code stability and avoid code loss and damage. Track code modification history and easily roll back to previous versions. Collaborative development, multiple developers modify the code at the same time without conflict. Basic SVN Operations To use SVN, you need to install an SVN client, such as TortoiseSVN or SublimeMerge. Then you can follow these steps to perform basic operations: 1. Create the code base svnmkdirHttp://exampl

Detailed explanation of how to install and set up the EclipseSVN plug-in Eclipse is a widely used integrated development environment (IDE) that supports many different plug-ins to extend its functionality. One of them is the EclipseSVN plugin, which enables developers to interact with the Subversion version control system. This article will detail how to install and set up the EclipseSVN plug-in and provide specific code examples. Step 1: Install the EclipseSVN plug-in and open Eclipse

Under Linux, it is very difficult to directly use the svndiff command to view code modifications, so I searched for a better solution on the Internet, which is to use vimdiff as a code viewing tool for svndiff, especially for those who are accustomed to using vim. It is very convenient. When using the svndiff command to compare the modifications of a certain file, for example, if you execute the following command: $svndiff-r4420ngx_http_limit_req_module.c, the following command will actually be sent to the default diff program: -u-Lngx_http_limit_req_module.c(revision4420)-Lngx_

Installing SVN on CentOS is a very common operation. It is a powerful version control system that can be used to manage and track changes during software development. This article will introduce in detail how to install SVN on CentOS and provide some commonly used tools. Command line installation method. There are many ways to install SVN on CentOS. Two common installation methods will be introduced below. 1. Open the terminal and log in as the root user. 2. Run the following command to update the system package list: ```yumupdate3. Run the following command to install SVN: yuminstallsubversion4. After the installation is complete, you can verify whether SVN was successfully installed by running the following command: svn --v

Differences: 1. vss was developed by Microsoft and is paid, while svn is open source and free; 2. vss must have a client, while svn can use the client, command line mode, or read-only on the web page Access; 3. vss only supports windows systems, while svn supports windows and linux systems; 4. vss is a "lock-edit-unlock" mode, and svn defaults to a "modify-conflict-merge" mode; 5. The version number of vss corresponds is a single file, and the version number of svn corresponds to the entire version library.

As a Linux developer, you often need to use SVN to control project versions. For excellent developers, knowing how to check SVN versions is undoubtedly one of the essential skills. Today, I would like to take this opportunity to share my experience with you, hoping to help you better master this practical skill. 1. To install the SVN command line tool, please install the SVN command line tool in the Linux environment first! Please dial the terminal and then safely enter the following command to complete the installation: ```Dear user, please execute sudoapt-getinstallsubversion to install Subversion. 2. Connect to the SVN server After the installation is complete, we need to connect to the SVN server. Enter the following command:

As a commonly used server-side scripting language, PHP is widely used in the field of Web development due to its open source and cross-platform advantages. In the development of multi-person collaboration, version control is an indispensable tool. It can effectively manage the modification and update of source code and avoid conflicts caused by code out-of-synchronization among team members. As a popular version control tool, SVN is also widely used in PHP development. This article will introduce you to the basic knowledge of SVN version control in PHP development, including the installation of SVN.
