SVN 中的 pre-revprop-change 挂钩是什么?如何创建它?

发布于 2024-07-06 10:15:04 字数 114 浏览 8 评论 0原文

我想在存储库浏览器中编辑日志注释,并收到一条错误消息,指出存储库不存在 pre-revprop-change 挂钩。 除了有一个可怕的名字之外,什么是 pre-revprop-change 挂钩,以及如何创建它?

I wanted to edit a log comment in the repository browser and received an error message that no pre-revprop-change hook exists for the repository. Besides having a scary name, what is a pre-revprop-change hook, and how do I create it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

万劫不复 2024-07-13 10:15:04

对于 Windows,以下是示例批处理文件的链接,该文件仅允许更改日志消息(不允许更改其他属性):

http://ayria.livejournal.com/33438.html

基本上将下面的代码复制到文本文件中,并将其命名为 pre-revprop-change.bat 并将其保存在 \hooks 存储库的子目录。

@ECHO OFF
:: Set all parameters. Even though most are not used, in case you want to add
:: changes that allow, for example, editing of the author or addition of log messages.
set repository=%1
set revision=%2
set userName=%3
set propertyName=%4
set action=%5

:: Only allow the log message to be changed, but not author, etc.
if /I not "%propertyName%" == "svn:log" goto ERROR_PROPNAME

:: Only allow modification of a log message, not addition or deletion.
if /I not "%action%" == "M" goto ERROR_ACTION

:: Make sure that the new svn:log message is not empty.
set bIsEmpty=true
for /f "tokens=*" %%g in ('find /V ""') do (
set bIsEmpty=false
)
if "%bIsEmpty%" == "true" goto ERROR_EMPTY

goto :eof

:ERROR_EMPTY
echo Empty svn:log messages are not allowed. >&2
goto ERROR_EXIT

:ERROR_PROPNAME
echo Only changes to svn:log messages are allowed. >&2
goto ERROR_EXIT

:ERROR_ACTION
echo Only modifications to svn:log revision properties are allowed. >&2
goto ERROR_EXIT

:ERROR_EXIT
exit /b 1

For Windows, here's a link to an example batch file that only allows changes to the log message (not other properties):

http://ayria.livejournal.com/33438.html

Basically copy the code below into a text file and name it pre-revprop-change.bat and save it in the \hooks subdirectory for your repository.

@ECHO OFF
:: Set all parameters. Even though most are not used, in case you want to add
:: changes that allow, for example, editing of the author or addition of log messages.
set repository=%1
set revision=%2
set userName=%3
set propertyName=%4
set action=%5

:: Only allow the log message to be changed, but not author, etc.
if /I not "%propertyName%" == "svn:log" goto ERROR_PROPNAME

:: Only allow modification of a log message, not addition or deletion.
if /I not "%action%" == "M" goto ERROR_ACTION

:: Make sure that the new svn:log message is not empty.
set bIsEmpty=true
for /f "tokens=*" %%g in ('find /V ""') do (
set bIsEmpty=false
)
if "%bIsEmpty%" == "true" goto ERROR_EMPTY

goto :eof

:ERROR_EMPTY
echo Empty svn:log messages are not allowed. >&2
goto ERROR_EXIT

:ERROR_PROPNAME
echo Only changes to svn:log messages are allowed. >&2
goto ERROR_EXIT

:ERROR_ACTION
echo Only modifications to svn:log revision properties are allowed. >&2
goto ERROR_EXIT

:ERROR_EXIT
exit /b 1
最舍不得你 2024-07-13 10:15:04

基本上,它是在存储库上修改未版本控制的属性之前启动的脚本,以便您可以更精确地管理存储库上发生的情况。

SVN 发行版中有针对不同挂钩的模板,位于 /hooks 子目录中(*.tmpl,您必须根据您的操作系统对其进行编辑和重命名才能激活)。

Basically it's a script that is launched before unversioned property is modified on the repository, so that you can manage more precisely what's happening on your repository.

There are templates in the SVN distrib for different hooks, located in the /hooks subdirectory (*.tmpl that you have to edit and rename depending on your OS, to activate).

ˇ宁静的妩媚 2024-07-13 10:15:04

要让 Linux 允许编辑日志注释,

  • 请在存储库的 hooks 目录中找到文件 pre-revprop-change.tmpl
  • 将文件复制到同一目录,将其重命名为 pre-revprop-change
  • 授予文件执行权限(对于服务器用户,例如 www-data

已编辑:(谢谢到 lindes)

  • 之后,您可能必须编辑脚本以针对您想要允许的编辑类型返回退出值 0

For Linux to allow the edition of a log comment,

  • locate the file pre-revprop-change.tmpl in the hooks directory of your repository
  • copy the file to the same directory, renaming it to pre-revprop-change
  • give execute permission to the file (for the server user, e.g. www-data)

Edited: (thanks to lindes)

  • after that you might have to edit the script to return an exit value of 0 for the kind of edits, that you want to allow.
寒冷纷飞旳雪 2024-07-13 10:15:04

这是堆栈溢出问题的链接,其中包含许多常见的钩子 Subversion 钩子的常见类型,包括此处交叉发布的 Windows 的 pre-revprop-change 挂钩的原始来源。

您应该参考那里,因为它们可能会随着时间的推移而得到改进。

Here is the link to the stack overflow question with many common hooks Common Types of Subversion Hooks, including the original source of the pre-revprop-change hook for Windows cross-posted here.

You should refer there as they may get improved over time.

壹場煙雨 2024-07-13 10:15:04

谢谢#patmortech

,我添加了你的代码,“只有同一个用户才能更改他的代码”。

:: Only allow editing of the same user.
for /f "tokens=*" %%a in ( 
'"%VISUALSVN_SERVER%\bin\svnlook.exe" author -r %revision% %repository%') do ( 
set orgAuthor=%%a
)
if /I not "%userName%" == "%orgAuthor%" goto ERROR_SAME_USER

Thanks #patmortech

And I added your code which "only the same user can change his code".

:: Only allow editing of the same user.
for /f "tokens=*" %%a in ( 
'"%VISUALSVN_SERVER%\bin\svnlook.exe" author -r %revision% %repository%') do ( 
set orgAuthor=%%a
)
if /I not "%userName%" == "%orgAuthor%" goto ERROR_SAME_USER
冰之心 2024-07-13 10:15:04

如果您设法破译它,钩子脚本的名称并不那么可怕:它是预修订属性更改钩子。 简而言之, 的目的pre-revprop-change 钩子脚本用于控制未版本化(修订版)属性的更改并发送通知(例如,当修订版属性更改时发送电子邮件)。

Subversion 中有两种类型的属性:

  • 可以在文件和目录上设置的版本化属性(例如 svn:needs-lock 和 svn:mime-type ),以及
  • 未版本化的属性(在存储库修订版上设置的修订版)属性(例如,svn:logsvn:date)。

版本化属性具有历史记录,并且可以由对存储库具有读/写访问权限的普通用户进行操作。 另一方面,未版本化的属性没有任何历史记录,主要用于维护目的。 例如,如果您提交修订,它会立即获取包含提交的 UTC 时间的 svn:date、包含您的用户名的 svn:authorsvn:log 与您的提交日志消息(如果您指定了任何消息)。

正如我已经指出的,pre-revprop-change 挂钩脚本的目的是控制修订属性的更改。 您不希望有权访问存储库的每个人都能够修改所有修订版属性,因此默认情况下禁止更改修订版属性。 要允许用户更改属性,您必须创建 pre-revprop-change 挂钩。

最简单的钩子只能包含一行:exit 0。 它将允许任何经过身份验证的用户更改任何修订属性,并且不应在真实环境中使用。 在 Windows 上,您可以使用批处理脚本或基于 PowerShell 的脚本在 pre-revprop-change 挂钩中实现一些逻辑。

此 PowerShell 脚本仅允许更改 svn:log 属性并拒绝空日志消息。

# Store hook arguments into variables with mnemonic names
$repos    = $args[0]
$rev      = $args[1]
$user     = $args[2]
$propname = $args[3]
$action   = $args[4]

# Only allow changes to svn:log. The author, date and other revision
# properties cannot be changed
if ($propname -ne "svn:log")
{
  [Console]::Error.WriteLine("Only changes to 'svn:log' revision properties are allowed.")
  exit 1
}

# Only allow modifications to svn:log (no addition/overwrite or deletion)
if ($action -ne "M")
{
  [Console]::Error.WriteLine("Only modifications to 'svn:log' revision properties are allowed.")
  exit 2
}

# Read from the standard input while the first non-white-space characters
$datalines = ($input | where {$_.trim() -ne ""})
if ($datalines.length -lt 25)
{
  # Log message is empty. Show the error.
  [Console]::Error.WriteLine("Empty 'svn:log' properties are not allowed.")
  exit 3
}

exit 0

此批处理脚本仅允许“svnmgr”用户更改修订版本属性:

IF "%3" == "svnmgr" (goto :label1) else (echo "Only the svnmgr user may change revision properties" >&2 )

exit 1
goto :eof

:label1
exit 0

The name of the hook script is not so scary if you manage decipher it: it's pre revision property change hook. In short, the purpose of pre-revprop-change hook script is to control changes of unversioned (revision) properties and to send notifications (e.g. to send an email when revision property is changed).

There are 2 types of properties in Subversion:

  • versioned properties (e.g svn:needs-lock and svn:mime-type) that can be set on files and directories,
  • unversioned (revision) properties (e.g. svn:log and svn:date) that are set on repository revisions.

Versioned properties have history and can be manipulated by ordinary users who have Read / Write access to a repository. On the other hand, unversioned properties do not have any history and serve mostly maintenance purpose. For example, if you commit a revision it immediately gets svn:date with UTC time of your commit, svn:author with your username and svn:log with your commit log message (if you specified any).

As I already specified, the purpose of pre-revprop-change hook script is to control changes of revision properties. You don't want everyone who has access to a repository to be able to modify all revision properties, so changing revision properties is forbidden by default. To allow users to change properties, you have to create pre-revprop-change hook.

The simplest hook can contain just one line: exit 0. It will allow any authenticated user to change any revision property and it should not be used in real environment. On Windows, you can use batch script or PowerShell-based script to implement some logic within pre-revprop-change hook.

This PowerShell script allows to change svn:log property only and denies empty log messages.

# Store hook arguments into variables with mnemonic names
$repos    = $args[0]
$rev      = $args[1]
$user     = $args[2]
$propname = $args[3]
$action   = $args[4]

# Only allow changes to svn:log. The author, date and other revision
# properties cannot be changed
if ($propname -ne "svn:log")
{
  [Console]::Error.WriteLine("Only changes to 'svn:log' revision properties are allowed.")
  exit 1
}

# Only allow modifications to svn:log (no addition/overwrite or deletion)
if ($action -ne "M")
{
  [Console]::Error.WriteLine("Only modifications to 'svn:log' revision properties are allowed.")
  exit 2
}

# Read from the standard input while the first non-white-space characters
$datalines = ($input | where {$_.trim() -ne ""})
if ($datalines.length -lt 25)
{
  # Log message is empty. Show the error.
  [Console]::Error.WriteLine("Empty 'svn:log' properties are not allowed.")
  exit 3
}

exit 0

This batch script allows only "svnmgr" user to change revision properties:

IF "%3" == "svnmgr" (goto :label1) else (echo "Only the svnmgr user may change revision properties" >&2 )

exit 1
goto :eof

:label1
exit 0
伴我心暖 2024-07-13 10:15:04

如果您想保存对日志消息的更改,请使用 @patmortech 上面答案中的批处理脚本 (https://stackoverflow.com/ a/468475),
谁从 https://stackoverflow.com/a/68850 复制了脚本,
并在 if "%bIsEmpty%" == "true" goto ERROR_EMPTYgoto :eofbefore 之间添加这些行:

set outputFile=%repos%\log-change-history.txt

echo User '%user%' changes log message in rev %rev% on %date% %time%.>>%outputFile%
echo ----- Old message: ----->>%outputFile%
svnlook propget --revprop %repos% svn:log -r %rev% >>%outputFile%
echo.>>%outputFile%
echo ----- New message: ----->>%outputFile%
for /f "tokens=*" %%g in ('find /V ""') do (echo %%g >>%outputFile%)
echo ---------->>%outputFile%
echo.>>%outputFile%

它将创建一个文本文件 log-change-在服务器上的 repo 文件夹中保存history.txt 并附加每个日志更改通知。

If you want to save the changes on the log messages, use the batch script from the answer above from @patmortech (https://stackoverflow.com/a/468475),
who copied the script from https://stackoverflow.com/a/68850,
and add these lines between if "%bIsEmpty%" == "true" goto ERROR_EMPTY and goto :eofbefore:

set outputFile=%repos%\log-change-history.txt

echo User '%user%' changes log message in rev %rev% on %date% %time%.>>%outputFile%
echo ----- Old message: ----->>%outputFile%
svnlook propget --revprop %repos% svn:log -r %rev% >>%outputFile%
echo.>>%outputFile%
echo ----- New message: ----->>%outputFile%
for /f "tokens=*" %%g in ('find /V ""') do (echo %%g >>%outputFile%)
echo ---------->>%outputFile%
echo.>>%outputFile%

It will create a text file log-change-history.txt in the repo folder on the server and append each log change notification.

如果没结果 2024-07-13 10:15:04

对于电脑用户:
在 Windows Server 机器上使用时,.bat 扩展名对我不起作用。 我按照 Django Reinhardt 的建议使用 VisualSvn,它创建了一个带有 .cmd 扩展名的钩子。

For PC users:
The .bat extension did not work for me when used on Windows Server maching. I used VisualSvn as Django Reinhardt suggested, and it created a hook with a .cmd extension.

毁梦 2024-07-13 10:15:04
  1. 转到 SVN repo 目录的子文件夹“hooks”,例如“D:\SVN\hooks\”,
  2. 创建空文件“pre-revprop-change.bat”,
  3. 在文件中写入“exit 0”(不带“”)并保存它
  4. 并享受:)

(这个解决方案肯定有缺点,因为没有检查/禁止任何内容。但对于我的情况 - 只有我正在使用的本地存储库 - 它似乎有效。)

  1. Go to SVN repo directory into the subfolder "hooks", e.g. "D:\SVN\hooks\"
  2. create the empty file "pre-revprop-change.bat" there
  3. in the file write "exit 0" (without "") and save it
  4. enjoy :)

(This solution surely has drawbacks, as nothing is checked/prohibited. But for my case - a local repo that only I am using - it seems to work.)

ゞ花落谁相伴 2024-07-13 10:15:04

这对我来说在 Windows Server 上是最简单的:
在 VisualSVN 中右键单击您的存储库,然后选择属性...,然后选择挂钩选项卡。

选择预修订属性更改挂钩,单击编辑

我需要能够更改作者 - 这经常发生在多人使用的远程计算机上,我们错误地使用其他人存储的凭据进行签入。

以下是要粘贴的修改后的社区 wiki 脚本:

@ECHO OFF
:: Set all parameters. Even though most are not used, in case you want to add
:: changes that allow, for example, editing of the author or addition of log messages.
set repository=%1
set revision=%2
set userName=%3
set propertyName=%4
set action=%5

:: Only allow the author to be changed, but not message ("svn:log"), etc.
if /I not "%propertyName%" == "svn:author" goto ERROR_PROPNAME

:: Only allow modification of a log message, not addition or deletion.
if /I not "%action%" == "M" goto ERROR_ACTION

:: Make sure that the new svn:log message is not empty.
set bIsEmpty=true
for /f "tokens=*" %%g in ('find /V ""') do (
set bIsEmpty=false
)
if "%bIsEmpty%" == "true" goto ERROR_EMPTY

goto :eof

:ERROR_EMPTY
echo Empty svn:author messages are not allowed. >&2
goto ERROR_EXIT

:ERROR_PROPNAME
echo Only changes to svn:author messages are allowed. >&2
goto ERROR_EXIT

:ERROR_ACTION
echo Only modifications to svn:author revision properties are allowed. >&2
goto ERROR_EXIT

:ERROR_EXIT
exit /b 1

This was the easiest for me on a Windows Server:
In VisualSVN right-click your repository, then select Properties... and then the Hooks tab.

Select Pre-revision property change hook, click Edit.

I needed to be able to change the Author - it often happens on remote computers used by multiple people, that by mistake we check-in using someone else's stored credentials.

Here is the modified community wiki script to paste:

@ECHO OFF
:: Set all parameters. Even though most are not used, in case you want to add
:: changes that allow, for example, editing of the author or addition of log messages.
set repository=%1
set revision=%2
set userName=%3
set propertyName=%4
set action=%5

:: Only allow the author to be changed, but not message ("svn:log"), etc.
if /I not "%propertyName%" == "svn:author" goto ERROR_PROPNAME

:: Only allow modification of a log message, not addition or deletion.
if /I not "%action%" == "M" goto ERROR_ACTION

:: Make sure that the new svn:log message is not empty.
set bIsEmpty=true
for /f "tokens=*" %%g in ('find /V ""') do (
set bIsEmpty=false
)
if "%bIsEmpty%" == "true" goto ERROR_EMPTY

goto :eof

:ERROR_EMPTY
echo Empty svn:author messages are not allowed. >&2
goto ERROR_EXIT

:ERROR_PROPNAME
echo Only changes to svn:author messages are allowed. >&2
goto ERROR_EXIT

:ERROR_ACTION
echo Only modifications to svn:author revision properties are allowed. >&2
goto ERROR_EXIT

:ERROR_EXIT
exit /b 1
冬天旳寂寞 2024-07-13 10:15:04

正如 Alois Helmer 之前回答的那样,您需要在要允许修订注释编辑的 SVN 存储库内的 hooks 目录中找到文件 pre-revprop-change.tmpl

对我来说,创建一个带有 pre-revprop-change name 的副本就足够了,尽管您可以编辑它以仅允许某些用户修改评论或您有的其他一些需求。

然后,您必须使用chmod 755 pre-revprop-change授予常规读取和执行权限,

但是常规执行权限是不够的。 您需要在 SELinux 中为该脚本授予 Apache/HTTPD 执行权限,如下所示。

chcon -t httpd_exec_t pre-revprop-change

如果不这样做,您将收到以下错误,该错误提供的信息很少,并且很难与 SELinux 配置相关联。

svnrdump: E175008: Revprop change blocked by pre-revprop-change hook (exit code 255) with no output.

As Alois Helmer answered before, you need to locate the file pre-revprop-change.tmpl in the hooks directory inside the SVN repository you want to allow revision comments edition.

For me, to create a copy with pre-revprop-change name was sufficient, though you could edit it to allow only certain users to modify the comments or some other needs you have.

And then you must grant regular read and execution permissions using chmod 755 pre-revprop-change

But regular execution permissions are not enough. You need to give Apache/HTTPD execution grants in SELinux for that script like this.

chcon -t httpd_exec_t pre-revprop-change

If you not, you'll get the following error that gives little information and it's hard to relate to a SELinux conf.

svnrdump: E175008: Revprop change blocked by pre-revprop-change hook (exit code 255) with no output.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文