关于Svn通过脚本自动更新后的处理

关于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

 


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值