1
votes

I want to prevent users of my SVN repository checking in changes to certain files. I have done this by using the following pre-commit hook script. However the number of restricted files is growing, and its becoming very slow to commit changes. I was wondering if there was a more efficient way of coding it, I've played with changelists but I can't make that work.

Thanks in advance

pre-commit hook script (windows based SVN repository):

setlocal
:: Inputs from Subversion
set REPOS=%1%
set TXN=%2%

:: Checks if one of the reference files
Rem Check if the commit contains reference files
svnlook changed %REPOS% -t %TXN% | findstr /r /i "^.*referenceparts/part1.txt" > nul
if %errorlevel%==0 (goto RefPart)
svnlook changed %REPOS% -t %TXN% | findstr /r /i "^.*referenceparts/part2.txt" > nul
if %errorlevel%==0 (goto RefPart)
......
.....
etc etc

exit 0

:: Blocks the commit if part are reference
: RefPart
echo. 1>&2
echo ---------------------------------------------------------------------- 1>&2
echo Your commit has been cancelled because you are trying to change a      1>&2
echo part for a reference turbine! Please make a copy of this part and      1>&2
echo save it under a different name.                                        1>&2
echo ---------------------------------------------------------------------- 1>&2
echo. 1>&2
exit 1
2
You should probably find a different way of locking the files down, but perhaps only doing one svnlook changed %REPOS% -t %TXN% might help (I have no idea if that or the findstr are the bottleneck).crashmstr

2 Answers

3
votes

Break out the "reference turbine" into a different svn repository, build it as a library, and distribute it as a library. Then only give access to the "reference turbine" library to those who need it.

Checking out non-modifiable source code to be built hundreds of times by people who aren't authorized to change it is just a waste of electricity and time.

If you are concerned that they need to step through the reference turbine source during their debugging sessions, offer for distribution two version of the library, one with debugging symbols and the corresponding source code, and one without the debugging symbols. Most IDEs have the concept of loading a "source code" package to provide human readable text to accompany a debugging session.

0
votes

I'd rewrite this to use perl rather than a windows cmd script. Perl has much better regex support so you can make it a bit faster rather than using a script to look through all of the reference files - you can filter on directories and patterns instead.

Strawberry perl is easy to get running - download it, put the exe and perl dll in a directory on your path, job done.

Mind you, I also used to use findstr with a windows script to filter a list of file extensions which was fast. I wrote the results of svnlook changed to a file (don't forget to append the revnum to the filename and delete it afterwards) and used that as input to the findstr command with the /G option. Try that first.