SVN钩子 start-commit.tmpl 统计用户上传计数

本文介绍了一个Subversion (SVN) 的start-commit钩子脚本示例,该脚本用于记录用户的提交次数。当用户尝试提交更改时,此脚本将被调用,并更新用户的提交记录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

重写/%SVN_HOME%/Repos/hooks/start-commit.tmpl

改名为/%SVN_HOME%/Repos/hooks/start-commit

start-commit.tmpl修改如下:

 

#!/bin/sh

# START-COMMIT HOOK
#
# The start-commit hook is invoked before a Subversion txn is created
# in the process of doing a commit.  Subversion runs this hook
# by invoking a program (script, executable, binary, etc.) named
# 'start-commit' (for which this file is a template)
# with the following ordered arguments:
#
#   [1] REPOS-PATH   (the path to this repository)
#   [2] USER         (the authenticated user attempting to commit)
#
# 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 commit continues; but
# if it exits with failure (non-zero), the commit is stopped before
# a Subversion txn is created, and STDERR is returned to the client.
#
# On a Unix system, the normal procedure is to have 'start-commit'
# invoke other programs to do the real work, though it may do the
# work itself too.
#
# Note that 'start-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
# 'start-commit.bat' or 'start-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.collab.net/repos/svn/trunk/tools/hook-scripts/ and
# http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/


REPOS=$1
USER=$2

#记录用户COMMIT次数的文件
RECORDPATH=/svn/Repos/commitRecord/$USER
if [ -f $RECORDPATH ]; then
	#从文件中读取已经上传的次数
	COMMIT_TIMES=`cat $RECORDPATH | awk '{print $1}'`
	#清除之前的记录
	rm -f $RECORDPATH
else
	COMMIT_TIMES=0;
fi
#把次数加一
COMMIT_TIMES=`expr ${COMMIT_TIMES} + 1`
#写次数到记录文件
echo $COMMIT_TIMES >> $RECORDPATH

#commit-allower.pl --repository $REPOS --user $USER || exit 1
#special-auth-check.py --user $USER --auth-level 3 || exit 1

# All checks passed, so allow the commit.
exit 0

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值