php操作SVN版本服务器类代码
发布时间:2023-09-08 07:22:41
标签: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;
}
}


猜你喜欢
- 本文讲述了python开发之IDEL(Python GUI)的使用方法。分享给大家供大家参考,具体如下:在安装完Python后,我们希望能够
- --sql语句就用下面的存储过程 /*--数据导出Excel导出查询中的数据到Excel,包含字段名,文件为真正的Excel文件,如果文件不
- 目录1.一般的模型构造、训练、测试流程2.自定义损失和指标3.使用tf.data构造数据4.样本权重和类权重5.多输入多输出模型6.使用回
- Python借助AI和数据科学,目前已经攀爬到了编程语言生态链的顶级位置,可以说Python基本上与AI已经紧密捆绑在了一起了。为什么人工智
- 用css属性选择器可以有选择性地对链接样式进行控制,如让所有的外部链接都加一个小图标来标识其是一外部链接。但用css有弊端: 1、只支持Fi
- 安装Pycharm2020.1无法启动安装完成后,打开就闪退卸载干净以前的版本如果 C:\Users\用户名字\.PyCharm2019.*
- 理论傅立叶变换用于分析各种滤波器的频率特性,对于图像,2D离散傅里叶变换(DFT)用于找到频域.快速傅里叶变换(FFT)的快速算法用于计算D
- Django配置文件settings简单说明,包含时区语言等打开创建好的django工程,查看settings.py文件BASE_DIR =
- 第一种方法:A=[0]*8第二种方法:import numpy as np A=np.zeros(8)来源:https://blog.csd
- 多线程爬虫:即程序中的某些程序段并行执行,合理地设置多线程,可以让爬虫效率更高糗事百科段子普通爬虫和多线程爬虫分析该网址链接得出:https
- MOCK的意义1.接口测试等待开发完成接口开发之后再进行,不符合测试的尽早测试的基本原则,我们可以利用MOCK工具来模拟接口,减少对开发的依
- 实现思路是先获取到当前最上面活动的窗口信息,然后提取该窗口的名称信息。之后获取窗口的坐标信息,即左上角的开始坐标及右下角的结束坐标。最后直接
- hash//从井号 (#) 开始的 URL(锚)host//主机名和当前 URL 的端口号hostname//当前 URL 的主机名href
- 对于初学者来说,找到一个好的框架来学习或者项目开发都是非常有必要的,而当你有一定开发经验后,你应该选择适合当前业务需要的框架。我这里并不想探
- 我希望大家看到该标题就能让想象到它的功能: 1、WITH TEMPL
- 这两天一直在做课件,我个人一直不太喜欢PPT这个东西……能不用就不用,我个人特别崇尚极简风。谁让我们是程序员呢,所以就爱上了Jupyter写
- 一·算术运算符在python中,算术运算符与数学中的算术运算极为类似,只是有些运算符号有所差别。算术运算符的算术计算一
- 什么是数据库?数据库是存放数据的“仓库”, * 对此形象地描述为“电子化文件柜
- 图像文件是自己仿照mnist格式制作,每张图像大小为128*128import structimport matplotlib.pyplot
- 本文针对开发项目中遇到的问题,进行了汇总问题1:如何选择select的option里面的值? 首先会用到一个方法 onchange();这个