热门标签 | 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 ... [详细]
  • 本文详细介绍了SQL日志收缩的方法,包括截断日志和删除不需要的旧日志记录。通过备份日志和使用DBCC SHRINKFILE命令可以实现日志的收缩。同时,还介绍了截断日志的原理和注意事项,包括不能截断事务日志的活动部分和MinLSN的确定方法。通过本文的方法,可以有效减小逻辑日志的大小,提高数据库的性能。 ... [详细]
  • 本文介绍了使用AJAX的POST请求实现数据修改功能的方法。通过ajax-post技术,可以实现在输入某个id后,通过ajax技术调用post.jsp修改具有该id记录的姓名的值。文章还提到了AJAX的概念和作用,以及使用async参数和open()方法的注意事项。同时强调了不推荐使用async=false的情况,并解释了JavaScript等待服务器响应的机制。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • iOS超签签名服务器搭建及其优劣势
    本文介绍了搭建iOS超签签名服务器的原因和优势,包括不掉签、用户可以直接安装不需要信任、体验好等。同时也提到了超签的劣势,即一个证书只能安装100个,成本较高。文章还详细介绍了超签的实现原理,包括用户请求服务器安装mobileconfig文件、服务器调用苹果接口添加udid等步骤。最后,还提到了生成mobileconfig文件和导出AppleWorldwideDeveloperRelationsCertificationAuthority证书的方法。 ... [详细]
  • 本文讨论了如何使用Web.Config进行自定义配置节的配置转换。作者提到,他将msbuild设置为详细模式,但转换却忽略了带有替换转换的自定义部分的存在。 ... [详细]
  • 云原生应用最佳开发实践之十二原则(12factor)
    目录简介一、基准代码二、依赖三、配置四、后端配置五、构建、发布、运行六、进程七、端口绑定八、并发九、易处理十、开发与线上环境等价十一、日志十二、进程管理当 ... [详细]
  • 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是一种版本管理系统,是开源软件的基石。即使在沟通充分的情况下,多人维护同一份源代码的一定也会 ... [详细]
  • IamsettingupApacheserverwithTortoiseSVNforalocalsourcecoderepository.Ihaveobservedt ... [详细]
  • 双十一在家学用 Git
    对于所有的开发者来说,掌握一门代码版本控制系统都是必须的,无论是自己做项目,团队合作,工作中的合作,都离不开版 ... [详细]
  • TheProblem:-Iwhanttoperiodicalymakeabackupofmydatabase,forthispurpose ... [详细]
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社区 版权所有