php操作SVN版本服务器类代码

SvnPeer.php


代码如下:

<?php
/**
*
* This class for execute the external program of svn
*
* @auth Seven Yang <qineer@gmail.com>
*
*/
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("<br>", $output);
if (strpos($output, 'non-existent in that revision')) {
return false;
}
return "<br>" . $command . "<br>" . $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("<br>", $output);
if (strpos($output, 'Committed revision')) {
return true;
}
return "<br>" . $command . "<br>" . $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('<br>', $output);
if (strpos($output, 'Committed revision')) {
return true;
}
return "<br>" . $command . "<br>" . $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('<br>', $output);
if (strpos($output, 'Committed revision')) {
return true;
}
return "<br>" . $command . "<br>" . $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('<br>', $output);
if (strpos($output, 'Committed revision')) {
return true;
}
return "<br>" . $command . "<br>" . $output;
}
static public function diff($pathA, $pathB)
{
$output = SvnPeer::runCmd("svn diff $pathA $pathB");
return implode('<br>', $output);
}
static public function checkout($url, $dir)
{
$command = "cd $dir && svn co $url";
$output = SvnPeer::runCmd($command);
$output = implode('<br>', $output);
if (strstr($output, 'Checked out revision')) {
return true;
}
return "<br>" . $command . "<br>" . $output;
}
static public function update($path)
{
$command = "cd $path && svn up";
$output = SvnPeer::runCmd($command);
$output = implode('<br>', $output);
preg_match_all("/[0-9]+/", $output, $ret);
if (!$ret[0][0]){
return "<br>" . $command . "<br>" . $output;
}
return $ret[0][0];
}
static public function merge($revision, $url, $dir)
{
$command = "cd $dir && svn merge -r1:$revision $url";
$output = implode('<br>', SvnPeer::runCmd($command));
if (strstr($output, 'Text conflicts')) {
return 'Command: ' . $command .'<br>'. $output;
}
return true;
}
static public function commit($dir, $comment)
{
$command = "cd $dir && svn commit -m'$comment'";
$output = implode('<br>', 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('<br>', $output);
preg_match_all("/[0-9]+/", $output, $ret);
if (!$ret[0][0]){
return "<br>" . $command . "<br>" . $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;
}
}

(0)

相关推荐

  • 解决常见的Eclipse SVN插件报错方法详解

    在学习SVN的过程中,你经常会遇到SVN插件问题,本文介绍一下在安装SVN插件时常见Eclipse SVN插件报错信息问题,希望本文介绍对你的学习有所帮助. AD: 本节和大家一起看一下SVN插件在安装过程中遇到的常见Eclipse SVN插件报错信息,和大家一起分享一下,希望通过本节的介绍大家知道当出现SVN插件报错时该如何处理. 常见Eclipse SVN插件报错信息: 1.update-rHEADD:/dev/workforceWorkingcopynotlocked;thisisprob

  • 基于Eclipse中SVN图标不显示的解决方法

    在用Eclipse做开发的时候,用到了svn版本控制器,这天当我打开Eclipse的时候,发现项目里面的所有文件前的版本号以及状态图标都不显示了,即所有的svn图标不显示了,这是怎么回事,关掉Eclipse重新启动了一遍,还是不凑效.可以确认的是当进行文件的更新提交的时候都可以正常进行,但就是不显示文件svn的版本号及状态图标,经过摸索 ,解决方法如下:如果没有汉化是英文版的话,在菜单栏中:windows ->preferences->General->Appearance->La

  • 基于SVN源码服务器搭建(详细教程分析)

    一.引言笔者曾经试图在网上搜索一篇关于SVN源代码服务器搭建方面的中文技术文章,可惜,所找到的,要么是不完整,要么就是对笔者没什么帮助的文章,TortoiseSvn的帮助文档固然强大,但因为是英文,不是很适合来作为入门者使用:毕竟,TortoiseSvn是一个客户端,服务器端的配置也很重要.一年前,笔者刚刚毕业,初入公司,在进行开发时,由于没有进行软件代码版本管理,导致的结果是•软件一天一个版本•Bug日益增加且隐藏很深•代码无法向前回溯•几个月前修正过的Bug在几个月后又重新出现由于最近公司决

  • Windows下SVN服务器搭建方法整理(apache)

    本节和大家谈谈Windows下SVN服务器搭建问题,在这里拿出来和大家分享一下,希望对大家有用. 1,软件下载 Windows下SVN服务器搭建,下载Subversion服务器程序.到官方网站的下载二进制安装文件,来到二进制包下载部分,找到WindowsNT,2000,XPand2003部分,然后选择"thisdirectory",这样我们可以看到许多下载的内容,目前可以下载svn-1.4.0-setup.exe.下载Subversion的Windows客户端TortoiseSVN.T

  • 清除svn文件的bat脚本整理

    第一个:比较直接的代码,循环删除当前目录及子目录下所有的SVN文件 复制代码 代码如下: @echo on color 2f mode con: cols=80 lines=25 @REM @echo 正在清理SVN文件,请稍候...... @rem 循环删除当前目录及子目录下所有的SVN文件 @rem for /r . %%a in (.) do @if exist "%%a\.svn" @echo "%%a\.svn" @for /r . %%a in (.)

  • shell脚本从SVN推送到多台服务器的代码

    复制代码 代码如下: SRCDIR=/letv/data/www/htdocs_user/MOD=userIP_LIST=(192.126.32.92 192.126.32.93 192.181.155.160 192.181.155.214 192.181.155.215 192.126.32.171) for i in ${IP_LIST[*]}do        echo -e "\n\nPUSH == $i == \n"        /usr/bin/rsync -vzrto

  • Windows SVN服务器搭建方法

    这里我就介绍一个在Windows环境下简单快速搭建SVN服务器的方法.通常的SVN服务器是搭建在Linux等系统下,例如用Apache+SVN配置,Linux下的SVN性能会非常好,但配置有些繁琐,如果SVN服务器只有自己使用,那么可以直接把SVN服务器搭建在个人Windows环境下使用. 目前较为简单的方案是VisualSVN Server.该SVN服务器是免费的,支持Windows NT, 2000, XP and 2003等环境,安装非常简单. 安装的时候可以选择SVN走http协议还是h

  • 在Fedora 10下配置SVN服务器的步骤

    svn服务器有2种运行方式:独立服务器和借助apache.2种方式各有利弊. svn存储版本数据也有2种方式:BDB和FSFS.因为BDB方式在服务器中断时,有可能锁住数据(我在搞ldap时就深受其害,没法根治),所以还是FSFS方式更安全一点. 1.安装subversion: yum install subversion.i386 (注;在mandriva下面需要安装urpmi subversion subversion-server subversion-tool) 2.创建subversi

  • 解析zend studio中直接导入svn中的项目的方法步骤

    1.在zend-studio中的项目explorer中右键->import->选择svn->project from svn->next->选择create new ...location->url里面输入项目的地址:例如:svn://192.168.1.230/xuexi. 2.在下面输入你登陆svn的用户名和密码,然后,选中save password.之后点击next. 3.之后这步非常重要,很容易搞的新手不知道怎么做的一步.因为路径对了,用户名密码都对了,但是到这

  • VisualSVN Server的配置和使用方法 图文

    1.为什么要用VisualSVN Server,而不用Subversion? 回答: 因为如果直接使用Subversion,那么在Windows 系统上,要想让它随系统启动,就要封装SVN Server为windws service,还要通过修改配置文件来控制用户权限,另外如果要想以Web方式[http协议]访问,一般还要安装配置Apache,如果是新手,岂不是很头痛?而VisualSVN Serve集成了Subversion和Apache,省去了以上所有的麻烦.安装的时候SVN Server已

  • 使用svn进行版本控制

    我使用系统是: Microsoft Windows xp sp2 第一:下载软件 有两个软件需要下载的:Subversion和TortoiseSVNSubversion 下载地址:http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91TortoiseSVN下载地址:http://tortoisesvn.net/downloads (有些文档说必备软件还有Apache,但这么说法的大多是较旧的文档这么提到,随着软件

  • linux下安装配置svn独立服务器的步骤分享

    file:/// 直接版本库访问(本地磁盘). http:// 通过配置Subversion的Apache服务器的WebDAV协议. https:// 与http://相似,但是包括SSL加密. svn:// 通过svnserve服务自定义的协议. svn+ssh:// 与svn://相似,但通过SSH封装 svn存储版本数据也有2种方式:BDB和FSFS.因为BDB方式在服务器中断时,有可能锁住数据,所以还是FSFS方式更安全一点.1. svn服务器安装操作系统: Redhat Linux A

  • 让你知道什么是 SVN

    subversion(简称svn)是近年来崛起的版本管理工具,是cvs的接班人.目前,绝大多数开源软件都使用svn作为代码版本管理软件. svn服务器有2种运行方式:独立服务器和借助apache.2种方式各有利弊. svn存储版本数据也有2种方式:BDB和FSFS.因为BDB方式在服务器中断时,有可能锁住数据(我在搞ldap时就深受其害,没法根治),所以还是FSFS方式更安全一点. 详见subversion.安全领域的SVNSVN站在更高层次上对现在的安全产品,从系统和控制的角度进行了"有机&q

  • WINDOWS下搭建SVN服务器端的步骤分享(Subversion)

    1.获取svn程序 2.安装 Subversion(以下简称SVN)的服务器端和客户端.下载下来的服务器端是个 zip压缩包,直接解压缩即可,比如我解压到 E:\subversion .客户端安装文件是个 exe 可执行文件,直接运行按提示安装即可,客户端安装完成后提示重启. 3.先建立空目录 E:\svn\repos1 ,注意一定是要空的.然后在 repos1 文件夹上"右键->TortoiseSVN->Create Repository here...",然后可以选择版

  • 让GoogleCode的SVN下的HTML文件在FireFox下正常显示.

    今天试了下发现GoogleCode提供的SVN中的HTML在Firefox中显示为HTML源文件 Google了一下,找到了答案: 如果正常显示需要在SVN提交文件时设置svn:mime-type 为 text/html.(http://blog.pluskid.org/?p=70) SVN客户端都支持自动配置具体配置方法如下(http://www.worldhello.net/wiki/SVN) -------------------------------------- 6.2 新增文件的属

  • 关于svn冲突的解决方法

    1.在冲突文件上右键----edit conflicts-----然后手动修改文件冲突的红色地方,其他地方可以不用管. 2.修改完后保存.将本地和svn里面的文件都保存好. 3.再在冲突的文件上面点击右键-----resolved,在弹出的窗口中点击相应文件并点击确定. 4.注意,这个时候并没有提交成功.这个时候只是说你已经将两个版本的文件改一致了.冲突的部分被你解决了,但是还没有将本地文件提交到svn里.所以,现在再点击文件右键----update.没有错误了就再在文件上右键-----comm

  • Windows下VisualSVN Server的安装与配置方法(图文)

    VisualSVN Server是免费的,而VisualSVN是收费的.VisualSVN是SVN的客户端,和Visual Studio集成在一起, VisualSvn Server是SVN的服务器端,包括Subversion.Apache和用户及权限管理 为什么在Windows下用VisualSVN Server而不用Subversion 因为如果直接使用Subversion,那么在Windows 系统上,要想让它随系统启动,就要封装SVN Server为windws service,还要通过

  • 删除SVN三种方法delSvn(windows+linux)

    一.在linux下 删除这些目录是很简单的,命令如下 find . -type d -name ".svn"|xargs rm -rf 或者 find . -type d -iname ".svn" -exec rm -rf {} \; 二.在windows下用以下法子: 1.在项目平级的目录,执行dos命令: xcopy project_dir project_dir_1 /s /i 2.或者在项目根目录执行以下dos命令 for /r . %%a in (.)

  • 浅析SVN常见问题及解决方法

    黄色感叹号(有冲突):--这是有冲突了,冲突就是说你对某个文件进行了修改,别人也对这个文件进行了修改,别人抢在你提交之前先提交了,这时你再提交就会被提示发生冲突,而不允许你提交,防止你的提交覆盖了别人的修改.要解决冲突,如果你确认你的修改是无效的,则用TSVN还原你的修改就行了:如果认为你的修改是正确的,别人的提交是无效的,那么用TSVN先标记为"解决冲突",然后就可以提交了:如果你认为你的修改和别人的修改都有一部分是有效的,那么你就把别人的修改手动合并到你的修改中,然后使用TSVN标

随机推荐