关于Svn通过脚本自动更新处理后续的工作
(1).利用Svn的hook脚本,调用你要执行的文件=>(处理)svn提交后的工作
(2).这里假设调用的是php,通过svn脚本执行php,代码示例为win环境下,Linux,需要修改执行命令
SET PHP=D:\AppServ\php5\php.exe
%PHP% -f D:\AppServ\www\svn_execute\run.php
(3).php脚本中通过系统命令调用svn.以下是我写的php的Svn调用类 (win下面可视化的VistualSvn其实也只是调用svn command,然后交给View来显示的),以下是简易版的php operation svn类
<?php
/**
* Created by PhpStorm.
* User: leboc
* Date: 14-1-8
* Time: 下午8:47
* @email:181391227@qq.com
* @auch:cx
*/
/***
* svn操作类
*/
class SvnClient{
public $username;//用户名
public $password;//密码
public $svnpath;//svn路径
public $serverpath;//服务器路径
public $bigVersion;
public $version_gap = 50;//版本跳跃间隔
/***
* 构造函数
*/
public function SvnClient($_username,$_password,$_svnpath,$_serverpath,$_bigVersion){
$this->username = $_username;
$this->password = $_password;
$this->svnpath = $_svnpath;
$this->serverpath = $_serverpath;
$this->bigVersion = $_bigVersion;
}
/**
* 比较差异
*/
public function diffFileList($pre_version,$last_version){
$pre_version = intval($pre_version);
$last_version = intval($last_version);
if($pre_version<0){
return false;
}
if($pre_version==$last_version || $last_version<$pre_version){
return false;
}
$command = 'svn diff '.$this->svnpath.' -r '.$pre_version.':'.$last_version.' --summarize';
return $this->executeSvnCommand($command);
}
/***
* 更新
*/
public function update(){
//svn up ".$Global_SVNPATH
$command = 'svn up '.$this->svnpath;
return $this->executeSvnCommand($command);
}
/**
* 取当前版本号
*/
public function getCurrVersion(){
// $command =
$info = $this->getInfo();
$version = $info[6];
$version = str_replace('Revision:','',$version);
return intval($version);
}
/*
* (
[0] => Path: TestSvn
[1] => Working Copy Root Path: D:\AppServ\www\XJSG\TestSvn
[2] => URL: https://pc201309251740/svn/TestSvn
[3] => Relative URL: ^/
[4] => Repository Root: https://pc201309251740/svn/TestSvn
[5] => Repository UUID: 0c48782a-9857-3349-8712-8c6ffea7a5b1
[6] => :Revision 48
[7] => Node Kind: directory
[8] => Schedule: normal
[9] => Last Changed Author: cx
[10] => Last Changed Rev: 48
[11] => Last Changed Date: 2014-01-07 23:48:07 +0800 (周二, 07 一月 2014)
[12] =>
)
* */
public function getInfo(){
$command = 'svn info '.$this->svnpath;
return $this->executeSvnCommand($command);
}
/**
* 取svn日志
*/
public function getLog(){
$command = 'svn log '.$this->svnpath;
return $this->executeSvnCommand($command);
}
/***
* svn执行命令行
*/
private function executeSvnCommand($command){
$output = '';
$extroot = " --username ".$this->username." --password ".$this->password;
$command.=$extroot;
// echo "<br/>".$command."<br/>";
exec($command,$output);
return $output;
}
/**
* 版本号规则
*/
public function getVersionRule($version_no){
// $this->bigVersion
$mid_version = intval($version_no/$this->version_gap);
$last_version = $version_no%$this->version_gap;
return $this->bigVersion.'.'.$mid_version.'.'.$last_version;
}
}
感谢这些年遇到所有一切美好的人和事 auth:cx,email:181391227@qq.com