svn版本之间修改文件目录获取并导入到本地
2016-04-26 16:18
381 查看
<html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <form method="post" action=""> <input type="text" name="version_from" placeholder="版本起始号"> <input type="text" name="version_to" placeholder="版本结束号"> <input type="submit" value="提交"> </form> </html> <?php /** * @desc svn版本之间文件目录获取 * @author Ezreal.yin * @date 2016-04-26 * @说明:确保svn安装的时候选择了command line client tools(默认不选择),把svn加入到环境变量 */ if ($_POST) { $version_from = isset($_POST['version_from']) ? $_POST['version_from'] : 0; $version_to = isset($_POST['version_to']) ? $_POST['version_to'] : 0; $url = 'svn://192.168.1.102/test/trunk'; //获取版本之间的文件变动 $arr = SvnPeer::getChangedFiles($url, $version_from-1, $version_to);//包含某个版本 $dir = array(); if (!empty($arr)) { foreach ($arr as $value) { if (strstr($value, 'svn:')) { //字符串处理获取变动文件路径 $dir[] = substr(strstr($value, 'svn:'), 37);//根据自己网站目录填写从什么位置分割 } } } if (!empty($dir)) { //生成变动文件夹 $path = date("Y-m-d") . '---' . $version_from. '-' . $version_to; if (!is_dir($path)) { mkdir($path, 0777); } //生成文件夹 foreach ($dir as $key => $value) { $dir_arr = explode('/', $value); if (!empty($dir_arr)) { $tmp_path = ''; foreach ($dir_arr as $k => $v) { //如果包含.php, .js, .css, .txt, .sql, .html等就是文件 if (strstr($v, '.php') || strstr($v, '.js') || strstr($v, '.css') || strstr($v, '.txt') || strstr($v, '.sql') || strstr($v, '.html')) { $file = SvnPeer::export($url.$tmp_path.'/'.$v, $path.$tmp_path); } else { $tmp_path .= '/' . $v; //文件夹不存在就创建文件夹 if(!is_dir($path.$tmp_path)) { mkdir($path.$tmp_path, 0777); } } } } } echo 'success'; } } class SvnPeer { const SVN_USERNAME = "test"; const SVN_PASSWORD = "test"; const SVN_CONFIG_DIR = "/tmp/";//(任意指定一个临时目录,解决svn: warning: Can't open file '/root/.subversion/servers': Permission denied) /** * 导出单个文件 * * @param $src string * @param $dst string * @return boolean * */ public static function export($src, $dst) { $command = "svn export $src $dst"; $output = self::runCmd ( $command ); $output = implode ( "<br />", $output ); if (strpos ( $output, 'Committed revision' )) { return true; } return "<br />" . $command . "<br />" . $output; } /** * 获取两个版本间修改的文件信息列表 * * @param $fromVersion int * @param $headRevision int * @param $$path string * * @return array */ public static function getChangedFiles($path, $fromVersion, $headRevision ){ $files = array(); $pipe = ""; $command = "svn diff -r {$fromVersion}:{$headRevision} --summarize $path"; $output = self::runCmd ( $command ,$pipe); $files = array_merge($files, $output); $command = "svn diff -r {$headRevision}:{$fromVersion} --summarize $path"; //文件删除可用逆向对比 $output = self::runCmd ( $command ,$pipe); $files = array_merge($files, $output); return array_unique($files); } /** * 运行CMD 返回结果 * @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; } }
相关文章推荐
- About SVN
- CentOS 6.5搭建Apache整合SVN 1.8.5服务器(多版本库权限配置)
- CentOS下SVN服务器测试版安装记录
- 如何在本机搭建SVN服务器
- Windows下搭建本地SVN服务器
- 让GoogleCode的SVN下的HTML文件在FireFox下正常显示.
- Windows下SVN服务器搭建方法整理(apache)
- Apache2+SVN+MYSQL认证 配置项详细步骤
- 在Fedora 10下配置SVN服务器的步骤
- 删除SVN三种方法delSvn(windows+linux)
- 探讨如何在Eclipse中过滤版本控制文件.svn
- linux下安装配置svn独立服务器的步骤分享
- 浅析SVN常见问题及解决方法
- 关于svn冲突的解决方法
- 基于Eclipse中SVN图标不显示的解决方法
- Shell脚本实现的基于SVN的代码提交量统计工具
- Ubuntu下定时提交代码到SVN服务器的Shell脚本分享
- 详解版本控制利器Git,SVN的异同以及适用范围