修改 svn 中每次编辑提交的作者 author 名字
2016-05-25 00:00
387 查看
<?php /** * 得到 author: * svn propget --revprop svn:author -r $r $url --username {$username} --password {$password}"; * 修改 author: * svn propset --revprop svn:author -r $r NEWVAL $url */ echo "Hello World!\n"; # 定义常量. define('SVN_ROOT', 'svn://svn.example.com/yourproject'); define('OPER_USER', 'adminuser'); define('OPER_PASSWORD', 'adminpassword'); define('MAX_REV', 12345); # 第一步: 得到所有作者, 并写入文件 svn_authors.php, 该文件第二步使用. if (false) { $all_authors = fetch_all_authors(); var_dump($all_authors); write_author_file($all_authors); } # 第二步: 修改 author, 根据第一步生成的映射文件, 注意: 该文件需要手工修改 old->new 名字映射. if (true) { update_svn_authors(); } exit(); # 修改所有 author. function update_svn_authors() { include 'svn_authors.php'; #var_dump($author_change_map); #exit(); for ($r = 1; $r < MAX_REV; ++$r) { $old_author = robust_get_author(SVN_ROOT, $r); if ($old_author === '') continue; $new_author = $author_change_map[$old_author]; if ($old_author === $new_author) continue; // 未改变. if (!$new_author) continue; // 未映射该用户, 则不要改变了. robust_change_author(SVN_ROOT, $r, $new_author); echo "Update rev $r author $old_author to $new_author\n"; } } function robust_change_author($svn_url, $r, $new_author) { for ($times = 0; $times < 50; ++$times) { if (change_author($svn_url, $r, $new_author)) return; sleep($times*1); } } # 修改指定 url 指定 rev 的 author. function change_author($url, $r, $new_author) { $username = OPER_USER; $password = OPER_PASSWORD; $cmd = "svn propset --revprop svn:author -r $r $new_author $url --username {$username} --password {$password}"; $output = null; $return_var = null; exec($cmd, $output, $return_var); if ($return_var === 0) return true; return false; } # 得到指定 $svn_url 的指定版本 $r 的编辑者. function get_author($svn_url, $r) { $username = OPER_USER; $password = OPER_PASSWORD; $cmd = "svn propget --revprop svn:author -r $r {$svn_url} --username {$username} --password {$password}"; #echo "The command is: $cmd \n"; $output = null; $return_var = null; exec($cmd, $output, $return_var); #var_dump($return_var); if ($return_var !== 0) { # 发生错误. return ''; } #var_dump($output); return $output[0]; } # 重复多次尝试获取 author. function robust_get_author($svn_url, $r) { # 最多尝试 50 次. for ($times = 0; $times < 50; ++$times) { $author = get_author($svn_url, $r); if ($author !== '') return $author; # 如果失败则休息一会再次试验. sleep(1 * $times); } return 'error'; } # 从 svn 库得到所有作者映射数组. function fetch_all_authors() { $all_authors = []; for ($r = 1; $r < MAX_REV; ++$r) { $author = robust_get_author(SVN_ROOT, $r); if ($author) { echo "svn:author at rev $r is: $author\n"; $all_authors[$author] = $author; } usleep(50*1000); # 暂停 50 ms write_author_file($all_authors); } return $all_authors; } # 输出所有作者到一个 php 文件中. function write_author_file($authors) { $file_name = 'svn_authors.php'; $fp = fopen($file_name, 'wt', false); fwrite($fp, "<?php\n"); fwrite($fp, "\$authors = [\n"); foreach ($authors as $a) { fwrite($fp, " '$a' => '$a',\n"); } fwrite($fp, " ];\n"); fwrite($fp, "\n"); fclose($fp); }
相关文章推荐
- css层叠样式表(2)——层叠样式表的使用
- php生成的csv, 无法完整显示带前导0的数字
- python 源码解析
- 集合(二):List接口。
- Shelve Instance 操作详解 - 每天5分钟玩转 OpenStack(38)
- python玩转大数据-(一)
- log2
- Java 代码块的执行顺序
- CentOS 6.4下安装Oracle 11gR2(x64)
- ORA-28000: the account is locked的解决办法
- oracle默认初始化用户名密码和密码修改
- 忘记oracle的sys用户密码怎么修改
- Linux下建立Oracle服务及其开机自启动
- 企业管理器控制台本地无法访问
- linux下Oracle的安装(二)
- centos7 关闭firewall安装iptables并配置
- 开源的服务发现可供选择的技术选型
- 详解Zoosk千万用户实时通信背后的开源技术[转]
- json字符串,json对象
- java获取真实ip地址