Automatic lock-modify-unlock: Difference between revisions

From SubversionWiki
Jump to navigation Jump to search
Anneb (talk | contribs)
New page: Different versions of binary files cannot be merged. Therefore versioning of binary files should follow the lock-modify-unlock model[http://svnbook.red-bean.com/en/1.4/svn.basic.vsn-models...
 
Anneb (talk | contribs)
No edit summary
Line 1: Line 1:
Different versions of binary files cannot be merged. Therefore versioning of binary files should follow the lock-modify-unlock model[http://svnbook.red-bean.com/en/1.4/svn.basic.vsn-models.html#svn.basic.vsn-models.lock-unlock]. You can force using this model for binary files with a  pre-commit script as part of the svn repository. This script verifies that property svn:needs-lock is set on binary files and denies the commit if the property is not available.
Different versions of binary files cannot be merged. Therefore versioning of binary files should follow the lock-modify-unlock model[http://svnbook.red-bean.com/en/1.4/svn.basic.vsn-models.html#svn.basic.vsn-models.lock-unlock].  
This setup uses the following three measures
* forces users to use property svn:needs-lock on newly added binary files. Denies commits when the property is not available
* sets the svn:needs-lock property on all already existing binary files in repositories
* configures users to automatically set property svn:needs-lock on newly added binary files




1) - create a pre-commit.cmd script in the repository\hooks directory (Windows only):
1) - create a pre-commit.cmd script in the repository\hooks directory. This script verifies that property svn:needs-lock is set on binary files and denies the commit if the property is not available (Windows only):
<pre>@echo off
<pre>@echo off
set REPOS=%1
set REPOS=%1

Revision as of 04:17, 8 December 2007

Different versions of binary files cannot be merged. Therefore versioning of binary files should follow the lock-modify-unlock model[1]. This setup uses the following three measures

  • forces users to use property svn:needs-lock on newly added binary files. Denies commits when the property is not available
  • sets the svn:needs-lock property on all already existing binary files in repositories
  • configures users to automatically set property svn:needs-lock on newly added binary files


1) - create a pre-commit.cmd script in the repository\hooks directory. This script verifies that property svn:needs-lock is set on binary files and denies the commit if the property is not available (Windows only):

@echo off
set REPOS=%1
set TRANSACTION=%2
set SVNLOOK="c:\Program Files\Subversion\apache2.2\bin\svnlook.exe"
set TEMP=c:\temp

if exist %TEMP%\tempfile%2 del %TEMP%\tempfile%2
for /f "tokens=1,2 usebackq" %%i in (`%SVNLOOK% changed -t %2 %1`) do @if %%i==A @echo %%j >> %TEMP%\tempfile%2
if not exist %TEMP%\tempfile%2 goto NOFILESADDED
for /f "usebackq" %%i in (`findstr /E /I /R "\.bmp.$ \.gif.$ \.ico.$ \.jpeg.$ \.jpg.$ \.png.$ \.tif.$ \.tiff.$ \.doc.$ \.jar.$ \.odt.$ \.pdf.$ \.ppt.$ \.swf.$ \.vsd.$ \.xls.$ \.zip.$" %TEMP%\tempfile%2`) do (
%SVNLOOK% propget -t %2 %1 svn:needs-lock %%i 1> nul 2> nul
if ERRORLEVEL 1 (
echo commit denied, binary files must have property svn:needs-lock >&2
type %TEMP%\tempfile%2 >&2
del %TEMP%\tempfile%2
EXIT /B 1
)
)
del %TEMP%\tempfile%2
:NOFILESADDED
EXIT /B 0

2) Recursively set svn:needs-lock property on binaries

If you need to apply svn:needs-lock on already existing binaries in a repository, do the following on a client (not on the svn server): - checkout a repository - add to following line to a cmd script (Windows only):

FOR /R c:\full\path\to\repository %%v in (*.bmp *.gif *.ico *.jpeg *.jpg *.png *.tif *.tiff *.doc *.jar *.odc *.odf *.odg *.odi *.odp *.ods *.odt *.pdf *.ppt *.ser *.swf *.vsd *.xls *.zip) do svn propset svn:needs-lock yes %%~fv

- run the script

3) Configure users to automatically use svn:needs-lock property on new binary files

New binary files should have the svn:needs-lock property set, this is verified by the script of step 1. This can be achieved automatically if users configure their svn client config file.

- under windows the SVN config file is "C:\Documents and Settings\[USER_NAME]\Application Data\Subversion\config"

Replace or merge the [miscellany] and [auto-props] sections in the svn config file with the following:

[miscellany]
enable-auto-props = yes

[auto-props]
### The format of the entries is:
###   file-name-pattern = propname[=value][;propname[=value]...]
### The file-name-pattern can contain wildcards (such as '*' and
### '?').  All entries which match will be applied to the file.
### Note that auto-props functionality must be enabled, which
### is typically done by setting the 'enable-auto-props' option.
*.bmp = svn:mime-type=image/bmp;svn:needs-lock=*
*.gif = svn:mime-type=image/gif;svn:needs-lock=*
*.ico = svn:mime-type=image/x-icon;svn:needs-lock=*
*.jpeg = svn:mime-type=image/jpeg;svn:needs-lock=*
*.jpg = svn:mime-type=image/jpeg;svn:needs-lock=*
*.png = svn:mime-type=image/png;svn:needs-lock=*
*.tif = svn:mime-type=image/tiff;svn:needs-lock=*
*.tiff = svn:mime-type=image/tiff;svn:needs-lock=*

*.doc = svn:mime-type=application/msword;svn:needs-lock=*
*.jar = svn:mime-type=application/octet-stream;svn:needs-lock=*
*.odc = svn:mime-type=application/vnd.oasis.opendocument.chart;svn:needs-lock=*
*.odf = svn:mime-type=application/vnd.oasis.opendocument.formula;svn:needs-lock=*
*.odg = svn:mime-type=application/vnd.oasis.opendocument.graphics;svn:needs-lock=*
*.odi = svn:mime-type=application/vnd.oasis.opendocument.image;svn:needs-lock=*
*.odp = svn:mime-type=application/vnd.oasis.opendocument.presentation;svn:needs-lock=*
*.ods = svn:mime-type=application/vnd.oasis.opendocument.spreadsheet;svn:needs-lock=*
*.odt = svn:mime-type=application/vnd.oasis.opendocument.text;svn:needs-lock=*
*.pdf = svn:mime-type=application/pdf;svn:needs-lock=*
*.ppt = svn:mime-type=application/vnd.ms-powerpoint;svn:needs-lock=*
*.ser = svn:mime-type=application/octet-stream;svn:needs-lock=*
*.swf = svn:mime-type=application/x-shockwave-flash;svn:needs-lock=*
*.vsd = svn:mime-type=application/x-visio;svn:needs-lock=*
*.xls = svn:mime-type=application/vnd.ms-excel;svn:needs-lock=*
*.zip = svn:mime-type=application/zip;svn:needs-lock=*