日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

svn添加钩子hook

發(fā)布時間:2025/3/20 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 svn添加钩子hook 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
svn 提供了鉤子功能,可以在提交代碼的幾個階段執(zhí)行腳本。 hooks目錄下的 pre-commit.tmpl是模板文件
vi pre-commit ----------------------------------------- #!/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


注意事項: 輸出錯誤信息到客戶端。 echo -e "\n 警告:必須填寫注釋!" 1>&2

使用?hook?,為了方便管理員 控制提交的過程?Subversion?提供了?hook?機制。當特定的 事件發(fā)生時,相應(yīng)的?hook?會被調(diào)用,?hook?其實就相當于特定 事件的處理函數(shù)。每個?hook?會得到與它所處理的事件相關(guān)的參數(shù),根據(jù)?hook?的 返回值,?Subversion?會決定是否繼續(xù)當前的提交過程。

當前?Subversion?提 供了?5?種可以安裝的?hook?:

事 件名

時 機

與?hook?交 互

一 般用途

start-commit

事務(wù)創(chuàng)建之前。

傳給?hook?的 參數(shù):

-?????????參 數(shù)?1?, 代碼庫路徑。

-?????????參 數(shù)?2?, 試圖提交的用戶名。

hook?的返回值:非?0?則 終止。

判斷用戶是否有權(quán)限進行提交 操作。

pre-commit

事務(wù)完成,但未提交。

-?????????參 數(shù)?1?, 代碼庫路徑。

-?????????參 數(shù)?2?, 事務(wù)名。

hook?的返回值:非?0?則 終止提交,操作回滾。

對提交內(nèi)容進行檢查。如要求 提交必須填寫提交信息。

post-commit

事務(wù)提交完畢,新的修訂版被 創(chuàng)建。

傳給?hook?的 參數(shù):

-?????????參 數(shù)?1?, 代碼庫路徑。

-?????????參 數(shù)?2?, 剛創(chuàng)建的修訂版號。

hook?的返回值被忽 略。

發(fā)送郵件通知,或備份代碼 庫。

pre-revprop-change

修改修訂版屬性(如提交時提 供的信息?message?)之前。

由于修訂版屬性一旦修改就會 永久的丟失,除非安裝這個事件的?hook?,subversion?的 客戶端不允許遠程修改修訂版屬性。

傳給?hook?的 參數(shù):

-?????????參 數(shù)?1?, 代碼庫路徑。

-?????????參 數(shù)?2?, 要修改的修訂版號。

-?????????參 數(shù)?3?, 操作用戶名。

-?????????要 修改的屬性。

hook?的返回值:非?0?則 終止。

保存修訂版屬性的改變記錄。

post-revprop-change

修訂版屬性值被修改之后。

如果沒有安裝?pre-revprop-change?的?hook?, 這個事件的?hook?不會被執(zhí)行。

傳給?hook?的 參數(shù):

-?????????參 數(shù)?1?, 代碼庫路徑。

-?????????參 數(shù)?2?, 要修改的修訂版號。

-?????????參 數(shù)?3?, 操作用戶名。

-?????????要 修改的屬性。

hook?的返回值被忽 略。

發(fā)送郵件通知。

hook?只有安裝之后才 會被執(zhí)行,在?Subversion?中這一過程相當簡單。只需將?hook?放 在代碼庫目錄的?hooks?子目錄下即可。為了能順利地找到它們,?Subversion?規(guī) 定?hook?的 命名與上表的事件名同名,如?pre-commit?的?hook?名就是?pre-commit?(請 確保它是可執(zhí)行的,在?windows?平臺下需要添加對應(yīng)的擴展名,如?bat?、?exe?、?com?。)。 創(chuàng)建代碼庫之后,?Subversion?會創(chuàng)建對應(yīng)的這?5?個事件的?hook?模 版。選取所需的模版,然后將其改名,在修改內(nèi)容。這樣?hook?就可以工作了,當 然請先確保?hook?本身能正常的執(zhí)行。

hook?的編寫非常簡 單,通常的做法:

-?????????法?1?: 使用所在平臺的腳本語言,如?unix?下的?shell?,或?windows/dos?的 批處理命令。

-?????????法?2?: 使用相關(guān)的語言,如?c?。

-?????????法?3?: 使用腳本語言,如?Python?或?perl?等實現(xiàn)主體。然后 通過法?1?來調(diào)用。

-?????????法?4?: 使用相關(guān)的語言實現(xiàn)主體,然后通過法?1?來調(diào)用。

這里給出在?windows?下 使用?bat?的例子,它實現(xiàn)了?pre-commit hook?主 要作用是檢查提交內(nèi)容中是否包含說明信息,如果沒有就放棄:

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

由于平臺的腳本系統(tǒng)功能畢竟 有限(?unix?下的不太清楚,不過批命令就太差了),建議采用方法?2?、?3?和?4?。 從簡易性方面的考慮,推薦方法?3?。因為象?python?就已經(jīng)提供了 一些常用的功能,如發(fā)送郵件。

最后,就是?subversion?以 正在存取代碼庫的過程的所屬用戶來執(zhí)行?hook?。因此,請確保這個用戶具有足夠的權(quán)限,可以訪問?hook?可 以直接或間接訪問的資源。


總結(jié)

以上是生活随笔為你收集整理的svn添加钩子hook的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。