在 Tortoise SVN 中禁用 Break Lock 的 Hook 脚本

发布于 2024-10-08 19:04:16 字数 820 浏览 7 评论 0原文

我需要对用户禁用 tortoiseSVN 中的中断锁定选项。我已经有一个 Pre-lock.BAT HOOK 可以阻止窃取锁定选项。任何人都可以向我提供一个阻止窃取锁定和打破锁定选项的脚本。请回复...

我现在拥有的 Hook 脚本是(它只阻止窃取锁定而不是破坏锁定)

@echo off

set SVN_REPOS=%1
set SVN_PATH=%2
set SVN_USER=%3

set lock_owner = ""
set lock_message = ""

REM Skip one row of output, take second token, and delimiter is " "
for /f "skip=1 tokens=2" %%U in ('svnlook lock %SVN_REPOS% %SVN_PATH%') do (
  set lock_owner=%%U
  goto :check_owner
)

:check_owner
if "%lock_owner%" == "" exit 0
if "%SVN_USER%" == "ADMIN" exit 0

for /f "skip=5 tokens=*" %%U in ('svnlook lock %SVN_REPOS% %SVN_PATH%') do (
  set lock_message=%%U
)

@echo on
if not "%lock_message%" == "" echo Lock message: %lock_message% 1>&2
echo Sorry %SVN_USER%. Error: %SVN_PATH% locked by %lock_owner%. 1>&2
exit 1 

I need to disable the break lock option in tortoiseSVN to the Users. I already have a Pre-lock.BAT HOOK that blocks the steal lock option. CAn anyone provide me a script that blocks both steal lock and break lock option. Kindly reply...

The Hook script that i have now is ( It blocks only steal lock and not break lock)

@echo off

set SVN_REPOS=%1
set SVN_PATH=%2
set SVN_USER=%3

set lock_owner = ""
set lock_message = ""

REM Skip one row of output, take second token, and delimiter is " "
for /f "skip=1 tokens=2" %%U in ('svnlook lock %SVN_REPOS% %SVN_PATH%') do (
  set lock_owner=%%U
  goto :check_owner
)

:check_owner
if "%lock_owner%" == "" exit 0
if "%SVN_USER%" == "ADMIN" exit 0

for /f "skip=5 tokens=*" %%U in ('svnlook lock %SVN_REPOS% %SVN_PATH%') do (
  set lock_message=%%U
)

@echo on
if not "%lock_message%" == "" echo Lock message: %lock_message% 1>&2
echo Sorry %SVN_USER%. Error: %SVN_PATH% locked by %lock_owner%. 1>&2
exit 1 

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

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

发布评论

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

评论(3

贩梦商人 2024-10-15 19:04:17

以防万一,如果有人需要此信息,则中断锁会使用另一个钩子(预解锁)。您可以使用相同的脚本来禁用中断锁定。

干杯,
阿米尼奥

Just in case that if someone needs this information there is another hook (pre-unlock) used by the break lock. You could use the same script to disable the break lock.

Cheers,
Arminio

︶ ̄淡然 2024-10-15 19:04:17
@echo off

REM [1] REPOS-PATH   (the path to this repository)
REM [2] PATH         (the path in the repository about to be locked)
REM [3] USER         (the user creating the lock)
REM [4] COMMENT      (the comment of the lock)
REM [5] STEAL-LOCK   (1 if the user is trying to steal the lock, else 0)

setlocal
::svn对代码资源库路径与文件路径里的右小括号敏感,需要对其转义
::代码资源库路径
set repos=%1 
set "repos=%repos:)=^)%"
::当前文件路径
set repPath=%2
set "repPath=%repPath:)=^)%"
set userName=%3
set isSteal=%5

rem NO_STEALING
::如果没有被锁定,则直接跳走结束处理
if /I '1'=='%isSteal%' goto NO_STEALING
REM echo aaa >>d:\log.txt
REM echo repos = %repos% >>d:\log.txt
REM echo repPath = %repPath% >>d:\log.txt
REM echo userName = %userName% >>d:\log.txt
rem if the path has been locked, find the Owner.
::这里是处理重点
::通过svnlook lock %repos% %repPath%,命令获取锁信息,例如:
::  UUID Token: opaquelocktoken:1707b1a0-8dd1-a94e-87d2-6569a115cd5c
::  Owner: ljz
::  Created: 2011-08-08 21:05:31 +0800 (周一, 08 八月 2011)
::  Expires:
::  Comment (1 line):
::通过findstr /r /n ".",将所有行的前面加上行号,前返回所有行,例如:
::  1:UUID Token: opaquelocktoken:1707b1a0-8dd1-a94e-87d2-6569a115cd5c
::  2:Owner: ljz
::  3:Created: 2011-08-08 21:05:31 +0800 (周一, 08 八月 2011)
::  4:Expires:
::  5:Comment (1 line):
::通过tokens=1,2,3 delims=: ,以:号与空格作为分隔符,将上述每一行分隔,并将前三段分别装入变量%%i,%%j,%%k
::通过if %%i == 2 set LockedName=%%k,把第二行分隔后的第三段装入变量LockedName,在这里,就是ljz
for /f "tokens=1,2,3 delims=: " %%i in ('svnlook lock %repos% %repPath% ^|findstr /r /n "."') do (
        if %%i == 2 set LockedName=%%k
        )

rem If we get no result from svnlook, there's no lock, allow the lock to happen.
::如果没有获取到锁定信息,则直接跳走结束处理
if not defined LockedName goto OK_EXIT

rem If the person locking matches the lock's owner, allow the lock to happen.
rem But this one won't effect, the SVN don't care if the person matchs, they just don't allow relock.
REM echo userName = %userName% >>d:\log.txt
REM echo LockedName = %LockedName% >>d:\log.txt
::如果锁定人与当前用户同名,则直接跳走结束处理
if /I '%LockedName%'=='%userName%' goto OK_EXIT

rem Otherwise, we've got an owner mismatch, so return failure:
:WRONG_PERSON
echo the path has been locked by %LockedName%, Pls contact %LockedName% to unlock it.>&2 
goto ERROR_EXIT 
:NO_STEALING
echo Stealing lock is not allowed at this server.>&2
:ERROR_EXIT
endlocal
exit 1
:OK_EXIT
endlocal
exit 0
@echo off

REM [1] REPOS-PATH   (the path to this repository)
REM [2] PATH         (the path in the repository about to be locked)
REM [3] USER         (the user creating the lock)
REM [4] COMMENT      (the comment of the lock)
REM [5] STEAL-LOCK   (1 if the user is trying to steal the lock, else 0)

setlocal
::svn对代码资源库路径与文件路径里的右小括号敏感,需要对其转义
::代码资源库路径
set repos=%1 
set "repos=%repos:)=^)%"
::当前文件路径
set repPath=%2
set "repPath=%repPath:)=^)%"
set userName=%3
set isSteal=%5

rem NO_STEALING
::如果没有被锁定,则直接跳走结束处理
if /I '1'=='%isSteal%' goto NO_STEALING
REM echo aaa >>d:\log.txt
REM echo repos = %repos% >>d:\log.txt
REM echo repPath = %repPath% >>d:\log.txt
REM echo userName = %userName% >>d:\log.txt
rem if the path has been locked, find the Owner.
::这里是处理重点
::通过svnlook lock %repos% %repPath%,命令获取锁信息,例如:
::  UUID Token: opaquelocktoken:1707b1a0-8dd1-a94e-87d2-6569a115cd5c
::  Owner: ljz
::  Created: 2011-08-08 21:05:31 +0800 (周一, 08 八月 2011)
::  Expires:
::  Comment (1 line):
::通过findstr /r /n ".",将所有行的前面加上行号,前返回所有行,例如:
::  1:UUID Token: opaquelocktoken:1707b1a0-8dd1-a94e-87d2-6569a115cd5c
::  2:Owner: ljz
::  3:Created: 2011-08-08 21:05:31 +0800 (周一, 08 八月 2011)
::  4:Expires:
::  5:Comment (1 line):
::通过tokens=1,2,3 delims=: ,以:号与空格作为分隔符,将上述每一行分隔,并将前三段分别装入变量%%i,%%j,%%k
::通过if %%i == 2 set LockedName=%%k,把第二行分隔后的第三段装入变量LockedName,在这里,就是ljz
for /f "tokens=1,2,3 delims=: " %%i in ('svnlook lock %repos% %repPath% ^|findstr /r /n "."') do (
        if %%i == 2 set LockedName=%%k
        )

rem If we get no result from svnlook, there's no lock, allow the lock to happen.
::如果没有获取到锁定信息,则直接跳走结束处理
if not defined LockedName goto OK_EXIT

rem If the person locking matches the lock's owner, allow the lock to happen.
rem But this one won't effect, the SVN don't care if the person matchs, they just don't allow relock.
REM echo userName = %userName% >>d:\log.txt
REM echo LockedName = %LockedName% >>d:\log.txt
::如果锁定人与当前用户同名,则直接跳走结束处理
if /I '%LockedName%'=='%userName%' goto OK_EXIT

rem Otherwise, we've got an owner mismatch, so return failure:
:WRONG_PERSON
echo the path has been locked by %LockedName%, Pls contact %LockedName% to unlock it.>&2 
goto ERROR_EXIT 
:NO_STEALING
echo Stealing lock is not allowed at this server.>&2
:ERROR_EXIT
endlocal
exit 1
:OK_EXIT
endlocal
exit 0
智商已欠费 2024-10-15 19:04:17

这是一个较短的版本,基于 ljzforever 已经发布的内容:

禁用窃取锁定(pre-lock.bat):

@echo off
REM https://www.visualsvn.com/support/svnbook/ref/reposhooks/pre-lock/
rem Repository path
set SVN_REPOS=%1
rem Versioned path that is to be locked
set SVN_PATH=%2
rem Authenticated username of the person attempting the lock
set SVN_USER=%3
rem Comment provided when the lock was created
set SVN_COMMENT=%4
REM 1 if the user is attempting to steal an existing lock; 0 otherwise
set SVN_STEAL=%5


if "%SVN_STEAL%" == "1" (
@echo on
echo THE STEAL LOCK OPTION IS DISABLED, PLEASE CONTACT ADMIN. 1>&2
exit 1 
)

禁用释放锁定(pre-unlock.bat):

@echo off
REM https://www.visualsvn.com/support/svnbook/ref/reposhooks/pre-unlock/
rem Repository path
set SVN_REPOS=%1
rem Versioned path which is to be unlocked
set SVN_PATH=%2
rem Authenticated username of the person attempting the unlock
set SVN_USER=%3
rem Lock token associated with the lock which is to be removed
set SVN_LOCK_TOKEN=%4
REM 1 if the user is attempting to break the lock; 0 otherwise
set SVN_BREAK=%5


if "%SVN_BREAK%" == "1" (
@echo on
echo THE BREAK LOCK OPTION IS DISABLED, PLEASE CONTACT ADMIN. 1>&2
exit 1 
)

Here is a shorter version, based on what ljzforever already posted:

Disable steal lock (pre-lock.bat):

@echo off
REM https://www.visualsvn.com/support/svnbook/ref/reposhooks/pre-lock/
rem Repository path
set SVN_REPOS=%1
rem Versioned path that is to be locked
set SVN_PATH=%2
rem Authenticated username of the person attempting the lock
set SVN_USER=%3
rem Comment provided when the lock was created
set SVN_COMMENT=%4
REM 1 if the user is attempting to steal an existing lock; 0 otherwise
set SVN_STEAL=%5


if "%SVN_STEAL%" == "1" (
@echo on
echo THE STEAL LOCK OPTION IS DISABLED, PLEASE CONTACT ADMIN. 1>&2
exit 1 
)

Disable release lock (pre-unlock.bat):

@echo off
REM https://www.visualsvn.com/support/svnbook/ref/reposhooks/pre-unlock/
rem Repository path
set SVN_REPOS=%1
rem Versioned path which is to be unlocked
set SVN_PATH=%2
rem Authenticated username of the person attempting the unlock
set SVN_USER=%3
rem Lock token associated with the lock which is to be removed
set SVN_LOCK_TOKEN=%4
REM 1 if the user is attempting to break the lock; 0 otherwise
set SVN_BREAK=%5


if "%SVN_BREAK%" == "1" (
@echo on
echo THE BREAK LOCK OPTION IS DISABLED, PLEASE CONTACT ADMIN. 1>&2
exit 1 
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文