<?php /** * Export the difference files between the specified versions, such as the difference between 100 and 200, to export all modifications of 100 (excluding)-200 (including) * "SVN command line" * 1, view the differences between versions * SVN diff-r 2359:2360--summarize--username Simon--password Simonfit * 2, export a version of the file to the local * SVN export-r 2360 svn://112.73.80.56/sjf/source/common/controller/wechatbasecontroller.class.php/root/2/files_ 2359_2360/common/controller/wechatbasecontroller.class.php--username Wenjianbao--password wjb888 * * */ root directory Define (' Site_path ', DirName (__file__)); SVN account Information $SVN _url = ' Svn://112.73.80.56/sjf/source '; $svn _username = ' Wenjianbao '; $svn _password = ' 5c95e61387c478c85ccf45e6a8ae6de3 '; $error _msg = ' You must useage like '. $_server[' argv '][0]. ' Old_version (excluding) new_version (including) '; if ($_server[' argc ']!= 3) { echo $error _msg; Exit (1); } if ($_server[' argv '][1] > $_server[' argv '][2]) { echo $error _msg; Exit (1); } $old _version = $_server[' argv '][1]; $new _version = $_server[' argv '][2]; $work _path = Site_path. "/file_${old_version}_${new_version}"; echo "starts analyzing version differences ... \ n"; $diff _cmd = "svn diff-r ${old_version}:${new_version}--summarize--username ${svn_username}--password ${svn_password}" ${svn_url} "; EXEC ($diff _cmd, $diff _list, $return); $diff _list = (array) $diff _list; foreach ($diff _list as $diff _info) { Echo $diff _info. "\ n"; } # Empty old data @system (' Rm-rf '. Site_path. '/file_* '); @system (' Rm-rf '. Site_path. '/diff_* '); # New Folder Dir_mkdir ($work _path); $diff _count = count ($diff _list); if ($diff _count < 1) { echo "There is no difference between versions"; Exit (1); } $diff _count = 0; $diff _file_path = Site_path. "/diff_${old_version}_${new_version}.txt"; # Export Version File echo "Start exporting ... \ n"; foreach ($diff _list as $diff _info) { if (Preg_match ([\w]+) \s+ (svn:.+)/', $diff _info, $matches)) { $SVN _file_mode = $matches [1]; $SVN _file_name = $matches [2]; A, M, D, AM is added and modified File is deleted if ($svn _file_mode = = ' D ') { Continue } $diff _count++; Write log File_write ($diff _file_path, $matches [0]. "\ n", ' a '); Download to Local $local _file_path = $work _path. Str_replace ($svn _url, ", $svn _file_name); $local _file_dir = dirname ($local _file_path); Dir_mkdir ($local _file_dir); $export _cmd = "svn export-r ${new_version} ${svn_file_name ${local_file_path}--username ${svn_username}--password ${s Vn_password} "; System ($export _cmd); } } echo "Altogether exports ${diff_count} difference file"; Exit (0); /** * Create Folder * * @param string $path folder path * @param int $mode access rights * @param bool $recursive is created recursively * @return BOOL */ function Dir_mkdir ($path = ', $mode = 0777, $recursive = True) { Clearstatcache (); if (!is_dir ($path)) { mkdir ($path, $mode, $recursive); return chmod ($path, $mode); } return true; } /** * Write file * * @param string $filename filename * @param string $text The text string to write * @param string $openmod text Write mode (' W ': Overwrite rewrite, ' A ': text append) * @return BOOL */ function File_write ($filename = ', $text = ', $openmod = ' W ') { if (@ $fp = fopen ($filename, $openmod)) { Flock ($FP, 2); Fwrite ($fp, $text); Fclose ($FP); return true; } Else { return false; } } |