热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用PHP编写的SVN类

以下是使用PHP编写的一个SVN类。需要的朋友可以参考下

以下是使用PHP编写的一个SVN类。需要的朋友可以参考下

代码如下:


/**
* SVN 外部命令 类
*
* @author rubekid
*
* @todo comment need addslashes for svn commit
*
*/
class SvnUtils {
/**
*
* svn 账号
*/
const SVN_USERNAME = "robot";
/**
* svn 密码
*/
const SVN_PASSWORD = "robot2013";
/**
* 配置文件目录 (任意指定一个临时目录,解决svn: warning: Can't open file '/root/.subversion/servers': Permission denied)
*/
const SVN_CONFIG_DIR = "/var/tmp/";

/**
* svn list
*
* @param $repository string
* @return boolean
*
*/
public static function ls($repository) {
$command = "sudo svn ls " . $repository;
$output = self::runCmd ( $command );
$output = implode ( "
", $output );
if (strpos ( $output, 'non-existent in that revision' )) {
return false;
}
return "
" . $command . "
" . $output;
}
/**
* svn copy
*
* @param $src string
* @param $dst string
* @param $comment string
* @return boolean
*
*/
public static function copy($src, $dst, $comment) {
$command = "sudo svn cp $src $dst -m '$comment'";
$output = self::runCmd ( $command );
$output = implode ( "
", $output );
if (strpos ( $output, 'Committed revision' )) {
return true;
}
return "
" . $command . "
" . $output;
}
/**
* svn delete
*
* @param $url string
* @param $comment string
* @return boolean
*
*/
public static function delete($url, $comment) {
$command = "sudo svn del $url -m '$comment'";
$output = self::runCmd ( $command );
$output = implode ( '
', $output );
if (strpos ( $output, 'Committed revision' )) {
return true;
}
return "
" . $command . "
" . $output;
}
/**
* svn move
*
* @param $src string
* @param $dst string
* @param $comment string
* @return boolean
*/
public static function move($src, $dst, $comment) {
$command = "sudo svn mv $src $dst -m '$comment'";
$output = self::runCmd ( $command );
$output = implode ( '
', $output );
if (strpos ( $output, 'Committed revision' )) {
return true;
}
return "
" . $command . "
" . $output;
}
/**
* svn mkdir
*
* @param $url string
* @param $comment string
* @return boolean
*/
public static function mkdir($url, $comment) {
$command = "sudo svn mkdir $url -m '$comment'";
$output = self::runCmd ( $command );
$output = implode ( '
', $output );
if (strpos ( $output, 'Committed revision' )) {
return true;
}
return "
" . $command . "
" . $output;
}
/**
* svn diff
* @param $pathA string
* @param $pathB string
* @return string
*/
public static function diff($pathA, $pathB) {
$output = self::runCmd ( "sudo svn diff $pathA $pathB" );
return implode ( '
', $output );
}
/**
* svn checkout
* @param $url string
* @param $dir string
* @return boolean
*/
public static function checkout($url, $dir) {
$command = "cd $dir && sudo svn co $url";
$output = self::runCmd ( $command );
$output = implode ( '
', $output );
if (strstr ( $output, 'Checked out revision' )) {
return true;
}
return "
" . $command . "
" . $output;
}
/**
* svn update
* @param $path string
*/
public static function update($path) {
$command = "cd $path && sudo svn up";
$output = self::runCmd ( $command );
$output = implode ( '
', $output );
preg_match_all ( "/[0-9]+/", $output, $ret );
if (! $ret [0] [0]) {
return "
" . $command . "
" . $output;
}
return $ret [0] [0];
}
/**
* svn merge
*
* @param $revision string
* @param $url string
* @param $dir string
*
* @return boolean
*/
public static function merge($revision, $url, $dir) {
$command = "cd $dir && sudo svn merge -r1:$revision $url";
$output = implode ( '
', self::runCmd ( $command ) );
if (strstr ( $output, 'Text conflicts' )) {
return 'Command: ' . $command . '
' . $output;
}
return true;
}
/**
* svn commit
*
* @param $dir string
* @param $comment string
*
* @return boolean
*/
public static function commit($dir, $comment) {
$command = "cd $dir && sudo svn commit -m'$comment'";
$output = implode ( '
', self::runCmd ( $command ) );
if (strpos ( $output, 'Committed revision' ) || empty ( $output )) {
return true;
}
return $output;
}
/**
* svn status (输出WC中文件和目录的状态)
*
* @param $dir string
*/
public static function getStatus($dir) {
$command = "cd $dir && sudo svn st";
return self::runCmd ( $command );
}
/**
* svn 冲突
*
* @param $dir string
* @return boolean
*/
public static function hasConflict($dir) {
$output = self::getStatus ( $dir );
foreach ( $output as $line ) {
if ( substr ( trim ( $line ), 0, 1 ) == 'C' || (substr ( trim ( $line ), 0, 1 ) == '!')) {
return true;
}
}
return false;
}
/**
* svn log
*
* @param $path string
* @return string
*
*/
public static function getLog($path) {
$command = "sudo svn log $path --xml";
$output = self::runCmd ( $command );
return implode ( '', $output );
}
/**
* svn info
* @param $path string
*/
public static function getPathRevision($path) {
$command = "sudo svn info $path --xml";
$output = self::runCmd ( $command );
$string = implode ( '', $output );
$xml = new SimpleXMLElement ( $string );
foreach ( $xml->entry [0]->attributes () as $key => $value ) {
if ( $key == 'revision' ) {
return $value;
}
}
}
/**
* 获取最新版本号
* @param $path string
*/
public static function getHeadRevision($path) {
$command = "cd $path && sudo svn up";
$output = self::runCmd ( $command );
$output = implode ( '
', $output );
preg_match_all ( "/[0-9]+/", $output, $ret );
if (! $ret [0] [0]) {
return "
" . $command . "
" . $output;
}
return $ret [0] [0];
}
/**
* 获取某文件最早版本号
*
* @param $filePath string
*
*/
public static function getFileFirstVersion($filePath){
$command = "sudo svn log {$filePath}";
$output = self::runCmd ( $command , "|grep -i ^r[0-9]* |awk '{print $1}'");
if(empty($output)){
return false;
}
return str_replace("r", '', $output[count($output)-1]);
}
/**
* 获取两个版本间修改的文件信息列表
*
* @param $fromVersion int
* @param $headRevision int
* @param $$path string
*
* @return array
*/
public static function getChangedFiles($path, $fromVersion, $headRevision ){
$files = array();
$pipe = "|grep -i ^Index:|awk -F : '{print $2}'";
$command = "svn diff -r {$fromVersion}:{$headRevision} $path";
$output = self::runCmd ( $command ,$pipe);
$files = array_merge($files, $output);
$command = "svn diff -r {$headRevision}:{$fromVersion} $path"; //文件删除可用逆向对比
$output = self::runCmd ( $command ,$pipe);
$files = array_merge($files, $output);
return array_unique($files);
}
/**
* 获取两个版本间某文件修改 的内容
*
* @param $filePath string
* @param $fromVersion int
* @param $headRevision int
*
* @return array
*/
public static function getChangedInfo( $filePath, $fromVersion, $headRevision ){
$command = "sudo svn diff -r {$fromVersion}:{$headRevision} $filePath";
$output = self::runCmd ( $command );
return $output;
}
/**
* 查看文件内容
*
* @param $filePath string
* @param $version int
*
* @return array
*/
public static function getFileContent($filePath, $version){
$command = "sudo svn cat -r {$version} $filePath";
$output = self::runCmd ( $command );
return $output;
}
/**
* Run a cmd and return result
* @param $command string
* @param $pipe string (可以增加管道对返回数据进行预筛选)
* @return array
*/
protected static function runCmd($command , $pipe ="") {
$authCommand = ' --username ' . self::SVN_USERNAME . ' --password ' . self::SVN_PASSWORD . ' --no-auth-cache --non-interactive --config-dir ' . self::SVN_CONFIG_DIR . '.subversion';
exec ( $command . $authCommand . " 2>&1" . $pipe, $output );
return $output;
}
}

,免备案空间,美国服务器,网站空间
推荐阅读
  • Java源代码安全审计(二):使用Fortify-sca工具进行maven项目安全审计
    本文介绍了使用Fortify-sca工具对maven项目进行安全审计的过程。作者通过对Fortify的研究和实践,记录了解决问题的学习过程。文章详细介绍了maven项目的处理流程,包括clean、build、Analyze和Report。在安装mvn后,作者遇到了一些错误,并通过Google和Stack Overflow等资源找到了解决方法。作者分享了将一段代码添加到pom.xml中的经验,并成功进行了mvn install。 ... [详细]
  • 本文介绍了使用cacti监控mssql 2005运行资源情况的操作步骤,包括安装必要的工具和驱动,测试mssql的连接,配置监控脚本等。通过php连接mssql来获取SQL 2005性能计算器的值,实现对mssql的监控。详细的操作步骤和代码请参考附件。 ... [详细]
  • SVN安装配置和使用
    简介:SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS、CVS,它采用了分支管理系统,它的设计目标就是取代CVS。互联网上很多版本控制服务已从CVS ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • 本文讨论了如何使用Web.Config进行自定义配置节的配置转换。作者提到,他将msbuild设置为详细模式,但转换却忽略了带有替换转换的自定义部分的存在。 ... [详细]
  • 本文介绍了如何使用JSONObiect和Gson相关方法实现json数据与kotlin对象的相互转换。首先解释了JSON的概念和数据格式,然后详细介绍了相关API,包括JSONObject和Gson的使用方法。接着讲解了如何将json格式的字符串转换为kotlin对象或List,以及如何将kotlin对象转换为json字符串。最后提到了使用Map封装json对象的特殊情况。文章还对JSON和XML进行了比较,指出了JSON的优势和缺点。 ... [详细]
  • svnWebUI:一款现代化的svn服务端管理软件
    svnWebUI是一款图形化管理服务端Subversion的配置工具,适用于非程序员使用。它解决了svn用户和权限配置繁琐且不便的问题,提供了现代化的web界面,让svn服务端管理变得轻松。演示地址:http://svn.nginxwebui.cn:6060。 ... [详细]
  • 腾讯安全平台部招聘安全工程师和数据分析工程师
    腾讯安全平台部正在招聘安全工程师和数据分析工程师。安全工程师负责安全问题和安全事件的跟踪和分析,提供安全测试技术支持;数据分析工程师负责安全产品相关系统数据统计和分析挖掘,通过用户行为数据建模为业务决策提供参考。招聘要求包括熟悉渗透测试和常见安全工具原理,精通Web漏洞,熟练使用多门编程语言等。有相关工作经验和在安全站点发表作品的候选人优先考虑。 ... [详细]
  • 云原生应用最佳开发实践之十二原则(12factor)
    目录简介一、基准代码二、依赖三、配置四、后端配置五、构建、发布、运行六、进程七、端口绑定八、并发九、易处理十、开发与线上环境等价十一、日志十二、进程管理当 ... [详细]
  • 【云计算】Dockerfile、镜像、容器快速入门 ... [详细]
  • Maven入门、什么是Maven、如何使用Maven、Maven的项目结构、简单的Mavenjava项目、Maven常用命令、Maven项目之间的引用、Maven依赖的传递、可选、排除day01
    目录第一节Maven入门1.1什么是Maven1.2如何使用Maven第一步:下载Maven第二步:配置Maven的环境变量第三步:了解什 ... [详细]
  • 1jdk去网站下载,然后拷贝到linux上;或直接wgethttp:download.oracle.comotn-pubjavajdk8u181-b1 ... [详细]
  • SVN 功能说明(简版)
    Subversion(SVN)是什么?SVN是一种版本管理系统,是开源软件的基石。即使在沟通充分的情况下,多人维护同一份源代码的一定也会 ... [详细]
author-avatar
mobiledu2502892183
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有