svn仓库迁移宿主机后,除邮件或DM知会外,还能如何对用户做出提示?
程序员文章站
2022-06-04 19:23:52
...
场景
svn仓库迁移宿主机后,配置库管理员往往会通过邮件或DM知会svn用户。当svn用户数量庞大,加上消息泛滥的情况,用户往往无法及时得知切换的事宜和方法,只有当用户svn ci时才提示报错无法check in,却在此时手忙脚乱地找支持人员却发现忙线中。
问题
那么我们还能如何对用户做出更高效提示?
思考
对于用户而言,需要在working copy的根目录执行
svn switch --relocate old_url new_url
在本例,我会以这个为例
svn switch --relocate svn+ssh://thesre.cn/repo01 svn+ssh://192.168.1.1/repo01
那么该提示,如何及时地出现在用户需要使用的时候呢?
svn Hook(svn钩子)
svn服务器提供了svn transition前中后各个时间点的钩子功能。本场景我们可以对提交时的start-commit钩子加以利用,使其帮我们自动提示用户切换事宜与操作步骤。
让我们来看看start-commit-tmpl
长什么样子,
[[email protected] hooks]$ cat templates/start-commit.tmpl| egrep -v '^#|^$'
REPOS="$1"
USER="$2"
commit-allower.pl --repository "$REPOS" --user "$USER" || exit 1
special-auth-check.py --user "$USER" --auth-level 3 || exit 1
exit 0
阅读该template的说明,可以看到位置参数1是仓库路径,位置参数2位用户名称。该template会执行两个脚本检查,只要有一个不通过就exit 1退出。
实践
如何来完成我们的提示?我们在原svn服务器的仓库上加上start-commit
,内容如下,
[[email protected] hooks]$ cat start-commit
#!/bin/sh
REPOS="$1"
USER="$2"
repo_name=`echo $REPOS|awk -F/ '{print $NF}'`
echo "Your repo $repo_name has been relocated, please run the following command to switch:" 1>&2
echo "" 1>&2
echo "svn switch --relocate svn+ssh://thesre.cn/$repo_name svn+ssh://192.168.1.1/$repo_name" 1>&2
exit 1
由上,我们可以输出三行包含事件与需要的操作的提示到stderr,原svn服务器会将start-commit的stderr输出给用户的terminal中。这样可以达到通知的效果。
如下所示:
╭─ben at MacBook Pro in /tmp/repo01 2021/04/19 - 22:00:34
╰─○ svn ci -m "by thesre." #切换前,用户提交到原服务器,将会得到提示
Adding folder01
Adding folder01/test.txt
Transmitting file data .svn: E165001: Commit failed (details follow):
svn: E165001: Commit blocked by start-commit hook (exit code 1) with output:
Your repo repo01 has been relocated, please run the following command to switch:
svn switch --relocate svn+ssh://thesre.cn/repo01 svn+ssh://192.168.1.1/repo01
svn用户看到上述提示,就知道如何进行切换了,
╭─ben at MacBook Pro in /tmp/repo01 2021/04/19 - 22:28:09
╰─○ svn info . | grep "Repository Root"
Repository Root: svn+ssh://thesre.cn/repo01
╭─ben at MacBook Pro in /tmp/repo01 2021/04/19 - 22:28:12
╰─○ svn switch --relocate svn+ssh://thesre.cn/repo01 svn+ssh://192.168.1.1/repo01 #执行切换命令
╭─ben at MacBook Pro in /tmp/repo01 2021/04/19 - 22:28:14
╰─○ svn info . | grep "Repository Root"
Repository Root: svn+ssh://192.168.1.1/repo01
这直接省了很多低效率的沟通。
参考文献
上一篇: 本地svn简单配置
下一篇: ArrayLIst(JDK1.8)