[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

SVN post-commit hook: shadow folders

From: Schneider, Wolf <Wolf.Schneider_at_icbc.com>
Date: Mon, 7 Feb 2011 22:48:05 +0000

We are trying to replicate the ShadowFolders feature of VSS, whereby each checked-in file that needs it gets mirrored to a reference directory. To do this, I wrote the following script, which works well except for the actual file copy - svn copy complains about the target folder not being a directory, although it most certainly is. My questions are a) what is wrong with my use of svn copy, and b) is there perhaps a better way to achieve the ShadowFolder feature? You'll note that my solution allows every file to have a specific shadow folder (by virtue of the associated property), so that they aren't all collected into a single box. It also skips any files without the property set so that only those files which need to be shadowed are copied (a necessity since only a fraction of the files being checked in to SVN need this mirroring). I've tried looking online for an existing script, but it doesn't seem like any have been made available yet. Thanks in advance for all suggestions you may have. Here's the scripts (and the associated log): Post-commit.bat: call %~dp0post-commit-run.bat %* >> %1/hooks/post-commit.log 2>&1 Post-commit-run.bat: @echo off rem Under Windows, SVN passes in the repository argument as drive:\path\to\repository, which SVN rem EXPORT treats as a working file -- to access the repository itself requires the use of the rem server URL (so that the request is sent using http). The easiest solution is to simply define rem that URL here and use it in the SVN calls. rem rem+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rem Note this means the EnvVar needs to be updated each time the script is moved to a new hooks folder!! rem+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ set REPURL=https://iss01sb299/svn/icbc rem Keep track of the SVN components being worked with set REPOSITORY=%1 set REVISION=%2 rem Get current date and time, formatting for readability for /F "tokens=1-4 delims=/ " %%i in ('date/t') do set CURRDT=%%j-%%k-%%l for /F "tokens=1-9 delims=:. " %%i in ('time/t') do set CURRTM=%%i:%%j%%k rem Process each file in the revision package for /f "tokens=2*" %%a in ('svnlook changed --revision %REVISION% %REPOSITORY%') do call :readProperties %%a exit /b rem ======================================================== rem Support functions rem ======================================================== rem ---------------------------------------------------------- rem Process the associated ShadowFolder property if it exists rem ---------------------------------------------------------- :readProperties for /f %%a in ('svnlook proplist -r %REVISION% %REPOSITORY% %1') do if [%%a] == [ShadowFolder] call :readShadowFolder %1 exit /b rem -------------------------------------------------------- rem Determine the value of the associated shadow folder rem -------------------------------------------------------- :readShadowFolder for /f %%a in ('svnlook propget -r %REVISION% %REPOSITORY% ShadowFolder %1') do call :processFile %1 %%a exit /b rem -------------------------------------------------------- rem If a shadow folder was defined, copy the file into it; note that this process is running rem as the server resource, so the shadow folder needs to be Write privileged for Everyone rem -------------------------------------------------------- :processFile set FPATH=%1 set FOLDER=%2 if [%FOLDER%] == [] exit /b rem Keep track of what we are doing echo (%CURRDT% %CURRTM%) Copying %FPATH% to %FOLDER% rem Extract the filename from the full path set FNAME= call :extractFileFromPath %FPATH% %FNAME% rem Copy the file to the indicated shadow folder svn copy -r %REVISION% %REPURL%/%FPATH% %FOLDER%/%FNAME% exit /b rem -------------------------------------------------------- rem Determine the file from a full pathname rem -------------------------------------------------------- :extractFileFromPath set FULLPATH=%1 set FNAME=%2 rem if we are at the last character stop the recursion if [%FULLPATH:~1%]==[] exit /b rem if the current character is a slash reduce the filename to what follows it if [%FULLPATH:~0,1%]==[/] set FNAME=%FULLPATH:~1% rem drop the leading character from the substring and recurse call :extractFileFromPath %FULLPATH:~1% %FNAME% exit /b Post-commit.log (note that I have also echoed the command used to the log - this line was removed from the above script for clarity): a) Writing to a local ShadowFolder (02-07-2011 11:31AM) Copying Development/CCSA/Tools/CCPW001/ccpw001.hr to C:\SVNtest\RefDir svn copy -r 601 https://iss01sb299/svn/icbc/Development/CCSA/Tools/CCPW001/ccpw001.hr C:\SVNtest\RefDir\ccpw001.hr svn: Path 'C:\SVNtest\RefDir' is not a directory b) Writing to a network shadow folder (02-07-2011 11:48AM) Copying Development/CCSA/Tools/CCPW001/ccpw001.h to \\MQ01DV299\LIBRARY\ReferenceDir\SVNtest svn copy -r 603 https://iss01sb299/svn/icbc/Development/CCSA/Tools/CCPW001/ccpw001.h \\MQ01DV299\LIBRARY\ReferenceDir\SVNtest\ccpw001.h svn: Path '\\mq01dv299\LIBRARY\ReferenceDir\SVNtest' is not a directory c) Removing the filename from the destination path (02-07-2011 12:00PM) Copying Development/CCSA/Tools/CCPW001/ccpw001.h to \\MQ01DV299\LIBRARY\ReferenceDir\SVNtest svn copy -r 604 https://iss01sb299/svn/icbc/Development/CCSA/Tools/CCPW001/ccpw001.h \\MQ01DV299\LIBRARY\ReferenceDir\SVNtest svn: Path '\\mq01dv299\LIBRARY\ReferenceDir\SVNtest' is not a directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Wolf Schneider IS Claims Services (Claim Initiation / Litigation) ICBC - building trust. driving confidence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404-35 Strachan-Bortnick Building (Head Office) 151 W. Esplanade North Vancouver British Columbia V7M 3H9 direct: 604-982-7296 facsimile: 604-443-4500 * Save trees. Print only when necessary. ------------------------------------------------------------ This email and any attachments are intended only for the named recipient and may contain confidential and/or privileged material. Any unauthorized copying, dissemination or other use by a person other than the named recipient of this communication is prohibited. If you received this in error or are not named as a recipient, please notify the sender and destroy all copies of this email immediately.
Received on 2011-02-07 23:58:03 CET

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.