svn版本之间修改文件目录获取并导入到本地



    
$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 ( "
", $output ); if (strpos ( $output, 'Committed revision' )) { return true; } return "
" . $command . "
" . $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; } }


你可能感兴趣的:(svn)