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;
}
}

在PHP开发中进行版本控制是很常见的操作,其中最常用的工具就是SVN(Subversion)。它可以方便地管理代码的历史版本以及协同开发过程中的代码更新。下面将介绍如何在PHP开发中使用SVN进行版本控制。一、安装SVN客户端和服务端首先需要安装SVN客户端和服务端。SVN客户端可以在SVN官网上下载对应的版本,安装即可,而服务端则需要自行搭建,具体方法可以

SVN简介SVN(Subversion)是一种集中式版本控制系统,用于管理和维护代码库。它允许多个开发者同时协作开发代码,并提供对代码历史修改的完整记录。通过使用SVN,开发者可以:保障代码稳定性,避免代码丢失和损坏。追踪代码修改历史,轻松回滚到之前的版本。协同开发,多个开发者同时修改代码而不会冲突。SVN基本操作要使用SVN,需要安装SVN客户端,例如TortoiseSVN或SublimeMerge。然后,您可以按照以下步骤执行基本操作:1.创建代码库svnmkdirHttp://exampl

EclipseSVN插件的安装和设置方法详解Eclipse是一个广泛使用的集成开发环境(IDE),它支持许多不同的插件来扩展其功能。其中之一是EclipseSVN插件,它使开发人员能够与Subversion版本控制系统进行交互。本文将详细介绍如何安装和设置EclipseSVN插件,并提供具体的代码示例。第一步:安装EclipseSVN插件打开Eclipse

在linux下,直接使用svndiff命令查看代码的修改是很吃力的,于是在网上搜索到了一个比较好的解决方案,就是让vimdiff作为svndiff的查看代码工具,尤其对于习惯用vim的人来说真的是很方便。当使用svndiff命令比较某个文件的修改前后时,例如执行以下命令:$svndiff-r4420ngx_http_limit_req_module.c那么实际会向默认的diff程序发送如下命令:-u-Lngx_http_limit_req_module.c(revision4420)-Lngx_

在CentOS上安装SVN是非常常见的操作,它是一个功能强大的版本控制系统,可以用于管理和追踪软件开发过程中的变更,本文将详细介绍如何在CentOS上安装SVN,并提供一些常用的命令行安装方法。在CentOS上安装SVN有多种方法,下面将介绍两种常用的安装方式。1.打开终端,以root用户身份登录。2.运行以下命令更新系统软件包列表:```yumupdate3.运行以下命令安装SVN:yuminstallsubversion4.安装完成后,可以通过运行以下命令验证SVN是否成功安装:svn--v

区别:1、vss是微软开发的,是收费的,而svn是开源免费的;2、vss必须有客户端,而svn可以用客户端,也可以用命令行模式,还可以用网页方式只读访问;3、vss只支持windows系统,而svn支持windows和linux系统;4、vss是“锁定-编辑-解锁”模式,svn默认是“修改-冲突-合并”模式;5、vss的版本号对应的是单个文件,svn的版本号对应的是整个版本库。

身为Linux开发人员,往往需要运用SVN控制项目版本。对于优秀开发者而言,熟知如何查阅SVN版本无疑是必备技能之一。今日,笔者想借此机会和各位分享自己的心得,希望能助您更好地掌握这一实用技巧。1.安装SVN命令行工具请先在Linux环境中安装SVN命令行工具哦!请拨通终端,然后稳妥地输入下面这条指令来完成安装吧:```尊敬的用户,请执行sudoapt-getinstallsubversion以安装Subversion。2.连接到SVN服务器安装完毕后,我们需要连接到SVN服务器。输入以下命令:

作为一种常用的服务器端脚本语言,PHP凭借其开源、跨平台的优势,被广泛应用于Web开发领域。而在多人协作的开发中,版本控制是一个不可或缺的工具,它可以有效地管理源代码的修改与更新,避免因团队成员之间代码不同步而造成的冲突。而SVN作为一款流行的版本控制工具,在PHP开发中的应用也十分广泛。本文将为大家介绍PHP开发中的SVN版本控制的基础知识,包括SVN的安


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

Dreamweaver CS6
視覺化網頁開發工具

WebStorm Mac版
好用的JavaScript開發工具