svn添加钩子hook
#!/bin/sh# PRE-COMMIT HOOK
#
# The pre-commit hook is invoked before a Subversion txn is
# committed. Subversion runs this hook by invoking a program
# (script, executable, binary, etc.) named 'pre-commit' (for which
# this file is a template), with the following ordered arguments:
#
# [1] REPOS-PATH (the path to this repository)
# [2] TXN-NAME (the name of the txn about to be committed)
#
# [STDIN] LOCK-TOKENS ** the lock tokens are passed via STDIN.
#
# If STDIN contains the line "LOCK-TOKENS:\n" (the "\n" denotes a
# single newline), the lines following it are the lock tokens for
# this commit. The end of the list is marked by a line containing
# only a newline character.
#
# Each lock token line consists of a URI-escaped path, followed
# by the separator character '|', followed by the lock token string,
# followed by a newline.
#
# The default working directory for the invocation is undefined, so
# the program should set one explicitly if it cares.
#
# If the hook program exits with success, the txn is committed; but
# if it exits with failure (non-zero), the txn is aborted, no commit
# takes place, and STDERR is returned to the client. The hook
# program can use the 'svnlook' utility to help it examine the txn.
#
# On a Unix system, the normal procedure is to have 'pre-commit'
# invoke other programs to do the real work, though it may do the
# work itself too.
#
# *** NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN, EXCEPT ***
# *** FOR REVISION PROPERTIES (like svn:log or svn:author). ***
#
# This is why we recommend using the read-only 'svnlook' utility.
# In the future, Subversion may enforce the rule that pre-commit
# hooks should not modify the versioned data in txns, or else come
# up with a mechanism to make it safe to do so (by informing the
# committing client of the changes). However, right now neither
# mechanism is implemented, so hook writers just have to be careful.
#
# Note that 'pre-commit' must be executable by the user(s) who will
# invoke it (typically the user httpd runs as), and that user must
# have filesystem-level permission to access the repository.
#
# On a Windows system, you should name the hook program
# 'pre-commit.bat' or 'pre-commit.exe',
# but the basic idea is the same.
#
# The hook program typically does not inherit the environment of
# its parent process. For example, a common problem is for the
# PATH environment variable to not be set to its usual value, so
# that subprograms fail to launch unless invoked via absolute path.
# If you're having unexpected problems with a hook program, the
# culprit may be unusual (or missing) environment variables.
#
# Here is an example hook script, for a Unix /bin/sh interpreter.
# For more examples and pre-written hooks, see those in
# the Subversion repository at
# http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and
# http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/REPOS="$1"
TXN="$2"# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook
# $SVNLOOK log -t "$TXN" "$REPOS" | \
# grep "[a-zA-Z0-9]" > /dev/null || exit 1# 通过svnlook获取提交时的日志信息
LOGMSG=$( $SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c )# 判断日志长度
if [ "$LOGMSG" -lt 1 ]; then
echo -e "\n 警告:必须填写注释!" 1>&2
exit 1
fi# Check that the author of this commit has the rights to perform
# the commit on the files and directories being modified.
# commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1# All checks passed, so allow the commit.
exit 0
使用 hook ,为了方便管理员 控制提交的过程 Subversion 提供了 hook 机制。当特定的 事件发生时,相应的 hook 会被调用, hook 其实就相当于特定 事件的处理函数。每个 hook 会得到与它所处理的事件相关的参数,根据 hook 的 返回值, Subversion 会决定是否继续当前的提交过程。
当前 Subversion 提 供了 5 种可以安装的 hook :
事 件名 |
时 机 |
与 hook 交 互 |
一 般用途 |
start-commit |
事务创建之前。 |
传给 hook 的 参数: - 参 数 1 , 代码库路径。 - 参 数 2 , 试图提交的用户名。 hook 的返回值:非 0 则 终止。 |
判断用户是否有权限进行提交 操作。 |
pre-commit |
事务完成,但未提交。 |
- 参 数 1 , 代码库路径。 - 参 数 2 , 事务名。 hook 的返回值:非 0 则 终止提交,操作回滚。 |
对提交内容进行检查。如要求 提交必须填写提交信息。 |
post-commit |
事务提交完毕,新的修订版被 创建。 |
传给 hook 的 参数: - 参 数 1 , 代码库路径。 - 参 数 2 , 刚创建的修订版号。 hook 的返回值被忽 略。 |
发送邮件通知,或备份代码 库。 |
pre-revprop-change |
修改修订版属性(如提交时提 供的信息 message )之前。 由于修订版属性一旦修改就会 永久的丢失,除非安装这个事件的 hook ,subversion 的 客户端不允许远程修改修订版属性。 |
传给 hook 的 参数: - 参 数 1 , 代码库路径。 - 参 数 2 , 要修改的修订版号。 - 参 数 3 , 操作用户名。 - 要 修改的属性。 hook 的返回值:非 0 则 终止。 |
保存修订版属性的改变记录。 |
post-revprop-change |
修订版属性值被修改之后。 如果没有安装 pre-revprop-change 的 hook , 这个事件的 hook 不会被执行。 |
传给 hook 的 参数: - 参 数 1 , 代码库路径。 - 参 数 2 , 要修改的修订版号。 - 参 数 3 , 操作用户名。 - 要 修改的属性。 hook 的返回值被忽 略。 |
发送邮件通知。 |
hook 只有安装之后才 会被执行,在 Subversion 中这一过程相当简单。只需将 hook 放 在代码库目录的 hooks 子目录下即可。为了能顺利地找到它们, Subversion 规 定 hook 的 命名与上表的事件名同名,如 pre-commit 的 hook 名就是 pre-commit (请 确保它是可执行的,在 windows 平台下需要添加对应的扩展名,如 bat 、 exe 、 com 。)。 创建代码库之后, Subversion 会创建对应的这 5 个事件的 hook 模 版。选取所需的模版,然后将其改名,在修改内容。这样 hook 就可以工作了,当 然请先确保 hook 本身能正常的执行。
hook 的编写非常简 单,通常的做法:
- 法 1 : 使用所在平台的脚本语言,如 unix 下的 shell ,或 windows/dos 的 批处理命令。
- 法 2 : 使用相关的语言,如 c 。
- 法 3 : 使用脚本语言,如 Python 或 perl 等实现主体。然后 通过法 1 来调用。
- 法 4 : 使用相关的语言实现主体,然后通过法 1 来调用。
这里给出在 windows 下 使用 bat 的例子,它实现了 pre-commit hook 主 要作用是检查提交内容中是否包含说明信息,如果没有就放弃:
set REPOS=%1 set TXN=%2 set SVNLOOK="D:/Program Files/Subversion/bin/SVNLOOK.exe" rem 此处不太严格, 因为把空格也算了 FOR /F "usebackq delims==" %%i IN (`%%SVNLOOK%% log -t %TXN% %REPOS%`) DO exit 0 exit 1 |
由于平台的脚本系统功能毕竟 有限( unix 下的不太清楚,不过批命令就太差了),建议采用方法 2 、 3 和 4 。 从简易性方面的考虑,推荐方法 3 。因为象 python 就已经提供了 一些常用的功能,如发送邮件。
最后,就是 subversion 以 正在存取代码库的过程的所属用户来执行 hook 。因此,请确保这个用户具有足够的权限,可以访问 hook 可 以直接或间接访问的资源。
svn添加钩子hook相关推荐
- 用键盘全局钩子[Hook]监视多进程键盘操作
用键盘全局钩子[Hook]监视多进程键盘操作 闲来无事,在WIN2K下用BCB5做了个键盘挂钩小程序,监视全局按键情况.Hook安放和回调函数放在一个单独DLL中,DLL原码如下: //------- ...
- 关于钩子(Hook)的使用
基本概念 钩子(Hook),是Windows消息处理机制的一个平台,应用程序可以在上面设置子程以监视指定窗口的某种消息,而且所监视的窗口可以是其他进程所创建的.当消息到达后,在目标窗口处理函数之前处理 ...
- 关于SVN添加无用的受控文件后,取消文件受控的方法
问题:关于SVN添加无用的受控文件后,取消文件受控的方法 答案:右键需要去掉受控的文件,选择TortoiseSVN->Unversion and add to ignore list->去 ...
- mysql 钩子函数_SetWindowsHookEx原理(如何使用钩子,使用钩子hook其他进程的函数)...
基本概念 钩子(Hook),是Windows消息处理机制的一个平台,应用程序可以在上面设置子程以监视指定窗口的某种消息,而且所监视的窗口可以是其他进程所创建的.当消息到达后,在目标窗口处理函数之前处理 ...
- java hook全局钩子_钩子(hook)
钩子(hook)编程 一.钩子介绍 1.1钩子的实现机制 钩子英文名叫Hook,是一种截获windows系统中某应用程序或者所有进程的消息的一种技术.下图是windows应用程序传递消息的过程: 如在 ...
- SVN钩子HOOK设置自动备份,服务本地可以看到所有更新内容。
可以实现SVN本机备份.或者其他备份.关键是可以保持有一份最新的SVN文件可以查看. 实现SVN与WEB同步,可以CO一个出来,也可以直接用自动更新web目录的方法,我们要在svn版本库中配置钩子来实 ...
- SVN钩子--hook
客户端提交SVN后,web服务器上自动update 先在服务器上co一份: svn --username longpan --password 123456 co svn://122.225.98.7 ...
- 为svn添加hook脚本
为了维护svn的log,方便后续查找某个模块的svn提交操作,今天终于动手写了一次svn的hook脚本.虽说功能不复杂,但是经历还是有点波折.特此记录 目标:输入的注释要遵照格式:[模块名]操作日志, ...
- Windows 全局钩子 Hook 详解
监控程序的实现 我们发现一些木马或其他病毒程序常常会将我们的键盘或鼠标的操作消息记录下来然后再将它发到他们指定的地方以实现监听.这种功能其他是利用了全局钩子将鼠标或键盘消息进行了截取,从而 ...
最新文章
- 项目中常用的 19 条 MySQL 优化总结
- [_CN] Eclipse精要与高级开发技术 note
- nginx phase handler的原理和选择
- 标准C/C++程序通过gSOAP调用WebService
- memcached命令行、Memcached数据导出和导入、php连接memcache、php的session存储到memcached...
- CentOS 7 巨大变动之 systemd 取代 SysV的Init
- windows2003修改远程桌面连接数
- 几个容易混淆的对齐概念
- 转:GCC,LLVM,Clang编译器对比
- 2.卷2(进程间通信)---Posix IPC
- jQuery Deferred对象
- 使用jvisualvm通过JMX的方式监控远程JVM运行状况
- WPS导入SQLSERVER的数据
- 两点间距离、点到直线距离、点到线段距离、线段到线段距离
- idm无法集成到谷歌浏览器怎么解决?
- iP138查询网,ip数据库
- 最常用的父子组件传值方式prop详解
- 计算机需要记笔记,如何优雅地用电脑记笔记
- c语言查表法编程流水灯,通过查表法的流水灯汇编程序
- JDK8新特性-Lambda
热门文章
- String s=new String(abc)创建了2个对象的原因
- Java IO流之对象流
- get方法报空指针_智能指针shared_ptr踩坑笔记
- (数据结构与算法)使用栈来实现综合计算器
- Gentoo 安装日记 04 (开启ssh服务,ssh登录虚拟机)
- 重新理解@Resource注解
- 乐易家智能机器人价格_安川焊接机器人价格多少钱?核心是质量好
- python爬取内容乱码_【提问】PYTHON 爬取下来的中文数据显示乱码
- python3 xpath_Python3使用Xpath解析网易云音乐歌手页面
- CF#1288A Deadline (函数求最值问题)