0

I have a slow running batch file that compiles a log of changes and then emails a user. I would like it not to cause the user's commits to perform slowly in TortoiseSVN.

@ECHO OFF
SET REPOS=%1
SET REV=%2
SET DIR=%REPOS%/hooks
SET PATH=%PATH%;%DIR%;C:\Utils 
SET WORKING_COPY=C:\path\to\local\copy\
SET SITENAME=MySiteName
SET SMTP_SERVER=11.11.11.11
SET EMAIL_TO=my@email.email
SET EMAIL_FROM=my@email.email
SET SUBJECT=SVN Update - %SITENAME% - rev %REV% - %REPOS%

svn cleanup %WORKING_COPY%
svn update %WORKING_COPY%


ECHO The following changes were made to the code: > %DIR%/email.txt
ECHO. >> %DIR%/email.txt


svn log %WORKING_COPY% -v -r "%REV%" >> %DIR%/email.txt


svn diff %WORKING_COPY% -c "%REV%" --no-diff-deleted >> %DIR%/email.txt


sendEmail -s %SMTP_SERVER% -t %EMAIL_TO% -f %EMAIL_FROM% -u "%SUBJECT%" -o message-file=%DIR%/email.txt

I realised that this was running slowly, so I moved it to another file "email-changes.bat" and created a simple batch to call this batch asynchronously.

@ECHO OFF
#START %1\hooks\email-changes.bat %1 %2
echo 'fired' > %1\hooks\test.log

If I comment out the "START" line it runs and finishes instantly. If I remove the comment it takes forever to complete. I thought that should allow the post-commit to return to SVN quickly.

Is there any way I can get the code to not hang in Subversion, but still complete the emailing task in the background?

digiguru
  • 12,724
  • 20
  • 61
  • 87
  • Yes looking at this, I should really go "post-commit > MSMQ > update & email" that way I won't get any nasty collisons if 2 people check in at once. – digiguru Apr 28 '11 at 15:55

1 Answers1

1

Try starting the real hook script in a separate process:

@ECHO OFF
cmd.exe /c START %1\hooks\email-changes.bat %1 %2
echo 'fired' > %1\hooks\test.log

if that doesn't work, find a tool that can start another bat file in a separate process/thread.

Stefan
  • 43,293
  • 10
  • 75
  • 117
  • Unfortunately, this didn't work - but big respect to you Stefan for all your work in TortoiseSVN. – digiguru Apr 28 '11 at 15:39
  • According to this: http://stackoverflow.com/questions/2190944/how-to-spawn-several-processes-from-the-windows-shell-and-wait-for-them-all-to-co it should work: start cmd /c proc1.bat – Stefan Apr 29 '11 at 11:15
  • Commenting out the cmd.exe line takes a few seconds to complete, but putting back in takes 1 minute 30 - and I always recieev the email before the command completes implying it's not working. – digiguru May 03 '11 at 09:28