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;
}
}
0
投稿
猜你喜欢
- xml(可扩展标记语言)看起来可能像某种w3c标准——现在没有什么实际影响,即使以后能派上用场,也是很久以后的事。但实际上,它现在已经得到了
- Dreamweaver(以下简称DW)提供了一种称为“Behavior”(行为)的机制,帮助你构建页面
- 远程(如通过互联网)连接access数据库的示例:首先,需要使用TCP/IP,ADO及XML(需要安装Microsoft XML 4.0。)
- 网页广告 Banner 设计图文手册:采用以下要点来改善你的BANNER。广告并不便宜。 确信你的广告被第一时间读到。使用像这样的Sans
- phpstorm配置debug环境众所周知,在渗透测试进行代码审计的时候,往往要审计代码的执行过程,亦或是在开发php项目的时候,需要了解代
- 去掉数据重复 增加两个字段 alter TABLE T_Employee Add FSubCompany VARchar(20); ALTE
- sql="select * from admin where users='"&users&&q
- 企业管理器中没有改数据库名的功能,如果一定要用企业管理器来实现,你可以备份数据库,然后还原,在还原时候可以指定另一个库名,然后再删除旧库就行
- 序 号前 缀使用的变量/范围或数据类型1a or arrArray2b or blnBoolean3bytByte4
- 你可能在使用MySQL过程中,各种意外导致数据库表的损坏,而且这些数据往往是最新的数据,通常不可能在备份数据中找到。本章将讲述如何检测MyS
- 是的,我在这里要说:注册表单将死(好拗口啊,但是不知道怎么翻译更恰当)。回想一下,当你想享受一个网站服务的时候,碰到的第一件事是什么?一个表
- 嗯,你可以说我很无聊。最近疯狂加班,今天才得以有时间搞一个CSS的像素图来消遣休息下。先看效果:运行代码框<!DOCTYPE html
- 在开发中有些敏感接口,例如用户余额提现接口,需要考虑在并 * 况下接口是否会发生问题。如果用户将自己的多条提现请求同时发送到服务器,代码能否扛
- 写完调用天气接口的demo之后,小程序调用天气接口并且渲染在页面,顺便再调用了一下美图的接口API:美图APIurlwxml:<vie
- 1.func Copy(dst Writer, src Reader) (written int64, err error)这个函数是从一个
- 本文介绍FCKeditor在Java环境下的使用方法。一、简介 功能:所见即所得,支持图片和Flash,工具栏可自由配置,使用简单兼容性:I
- <html> <head> <title>获取ACCESS数据库表名 -&
- 对于JavaScript对象的操作基本上都会调用底层的对象内部方法,我们可以看出在ES6标准中定了14种内部方法.双 [[]] 代表内部方法
- 说到这个话题,我们有个产品叫群组,为什么人们需要群组?简单说,群组就是个圈子,是有共同爱好和话题的人群聚在一起讨论、分享的地方。这个产品的诞
- 内容适应形式学习了死猫的文章,我今天也来说说有关内容和容器的关系。看标题你也许觉得有些囧,它和上一篇《形式追随内容?》看起来相反,而且好像从