SVN强制提交大于5个字符的日志,并且去掉前后空格

 

set SVN_BINDIR=C:\"Program Files"\"VisualSVN Server"\bin
set REPOS=%1
set TXN=%2
set s=%SVN_BINDIR%\svnlook log "%REPOS%" -t "%TXN%"
for /f "delims=" %%a in ('%s%') do set myvar=%%a
set logmess=%myvar%

:intercept_left
if "%myvar%"==" " goto err
if "%myvar:~0,1%"==" " set "myvar=%myvar:~1%"&goto intercept_left
:intercept_right
if "%myvar%"==" " goto err
if "%myvar:~-1%"==" " set "myvar=%myvar:~0,-1%"&goto intercept_right

set count=0
setlocal enabledelayedexpansion
:countgoto
set /a count+=1
for /f %%i in ("%count%") do if not "!myvar:~%%i,1!"=="" goto countgoto


if %count% lss 5 (goto err) else exit 0

:err
echo. 1>&2
echo Your commit has been blocked because your logmessage at least 5 1>&2
echo Please write a log message describing the purpose of your changes and 1>&2
echo then try committing again. -- Thank you 1>&2
exit 1

 

set s=%SVN_BINDIR%\svnlook log "%REPOS%" -t "%TXN%"  这个是得到提交时日志的命令

for /f "delims=" %%a in ('%s%') do set myvar=%%a   是把命令中返回的字符串赋值给变量myvar。

 

 

:intercept_left

if "%myvar%"==" " goto err

if "%myvar:~0,1%"==" " set "myvar=%myvar:~1%"&goto intercept_left

:intercept_right

if "%myvar%"==" " goto err

if "%myvar:~-1%"==" " set "myvar=%myvar:~0,-1%"&goto intercept_right

 

这个是去掉前后空格,但是如果去掉的过程中发现最后一个是" "说明就都是空格了,所以就跳到错误处

 

 

set count=0

setlocal enabledelayedexpansion

:countgoto

set /a count+=1

for /f %%i in ("%count%") do if not "!myvar:~%%i,1!"=="" goto countgoto

 

这个是统计有多少字符的

 

 

 

你可能感兴趣的:(SVN,dos)