有好长时间没有写过Blog了...具体的原因真是一大堆啊,不说也罢,反正,偶现在是回来了:)
嘿嘿.
The Return of the hBifTS.
这几天一直在玩SubVersion,据说是比CVS更加好用的,更加强大的版本控制系统...
它的优点有很多,具体就不在这里介绍了.随便Google一把,都会有一大堆的:)
SubVersion的Server的实现有两种形式,一种就是和Apache的集成,可以实现http/https的访问.而且还可以很方便的通过Apache的集成来实现Per-Directory的认证.
另一种方式就是使用svnserve.exe.这是SubVersion内置的服务器.使用起来要比与Apache要方便,快捷很多.
其功能也相差不了多少(厄,还是相差很多的.)
现在的一个问题就是使用svnserve的方式,不支持Per-Directory的权限认证.
让我们来考虑一下怎么实现Per-Directory的权限认证.
实现这样的方式,我们得得到当前提交者的UserName,然后就是提交者的提交的路径.有了这两个,就可以通过相应的权限规则来判断是否有权限提交到些目录下面.最后一个就是能确认提交或是取消提交,否则权限控制完全没有意义了:)
由于Svn是用C/C++写的,而且提供了相应的.h文件,便于二次开发/增加插件功能.但是对于C#而言,就是一个恶梦(想想成堆的结构的声明,函数的导入),幸好SubVersion提供了Hooks Script,可以让我们在Start-commit/pre-commit/post-commit的时候做我们想做的事.既然这样,实现一个类似Per-Directory的认证就不是很困难了:)
打开一个生成的SubVersion的代码仓库,在目录下面有一个Hooks的目录,进去,我们可以看到5个文件.
打开Pre-commit.tmpl文件看看说明:
# 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)
Name
svnlook author — Print the author.
Synopsis
svnlook author REPOS_PATH
Description
Print the author of a revision or transaction in the repository.
Switches
--revision (-r)
--transaction (-t)
Examples
svnlook author is handy, but not very exciting:
$ svnlook author -r 40 /usr/local/svn/repos
sally

Name
svnlook changed — Print the paths that were changed.
Synopsis
svnlook changed REPOS_PATH
Description
Print the paths that were changed in a particular revision or transaction, as well as an “svn update-style” status letter in the first column: A for added, D for deleted, and U for updated (modified).
Switches
--revision (-r)
--transaction (-t)
Examples
This shows a list of all the changed files in revision 39 of a test repository:
$ svnlook changed -r 39 /usr/local/svn/repos
A trunk/vendors/deli/
A trunk/vendors/deli/chips.txt
A trunk/vendors/deli/sandwich.txt
A trunk/vendors/deli/pickle.txt
