• SVN needslock 设置强制只读属性


    http://www.svnclub.com/?q=node/255 http://blog.csdn.net/pkrobbie/article/details/4466160 http://www.orcaware.com/svn/wiki/Automatic_lock-modify-unlock           Automatic lock-modify-unlock From SubversionWiki Jump to: navigation, search Different versions of binary files cannot be merged. Thereforeversioning of binary files should follow the lock-modify-unlockmodel[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 binaryfiles and denies the commit if the property is not available (Windowsonly): @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 As an alternative, this modification to the script above handles longfilenames and by default is setup to work with a VisualSVN Serverinstallation. set REPOS=%1 set TRANSACTION=%2 set SVNLOOK=c:\Progra~1\Visual~1\bin\svnlook.exe set TEMP=c:\Progra~1\Visual~1 if exist %TEMP%\tempfile%2 del %TEMP%\tempfile%2 REM Identify all property updates and added files in current transaction and print them to tempfile for /f "tokens=1,* usebackq" %%i in (`%SVNLOOK% changed -t %2 %1`) do @if %%i==A @echo %%j>> %TEMP%\tempfile%2 for /f "tokens=1,* usebackq" %%i in (`%SVNLOOK% changed -t %2 %1`) do @if %%i==_U @echo %%j>> %TEMP%\tempfile%2 REM If no property updates or file additions occurred go to the end of the script if not exist %TEMP%\tempfile%2 goto NOFILESADDED REM For each file with these extensions listed in the tempfile check that it has the needs-lock property set for /f "tokens=* 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 ( REM echo "%SVNLOOK% propget -t %2 %1 svn:needs-lock "%%i" 1> nul 2> nul" 1>&2 %SVNLOOK% propget -t %2 %1 svn:needs-lock "%%i" 1>&2 REM If the property wasn't set if ERRORLEVEL 1 ( REM Display a helpful error message to the user 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 Ifyou need to apply svn:needs-lock on already existing binaries in arepository, do the following on a client (not on the svn server): -checkout a repository - add to following line to a cmd script (Windowsonly): 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 propsetsvn:needs-lock yes %%~fv - run the script 3) Configure users to automatically use svn:needs-lock property on new binary files Newbinary files should have the svn:needs-lock property set, this isverified by the script of step 1. This can be achieved automatically ifusers 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=*     ------------------------------- 想在svn server端做一个检查,对于需要指定needs-lock的文件在添加的时候检查。 没有时间写出完整的脚本。先把查出的资料记一下。   第一步: svnlook changed ...   获取所有变化的文件,其中 A xxx是新加的   第二步:对于每一个新加的文件,判断后缀, svn pg needs-lock xxx 检查文件的属性 返回值为 * 没问题,其他报错。   做完了脚本   [python]view plaincopyprint?
    1. import sys, os, string
    2. import time
    3. SVNLOOK='svnlook.exe'
    4. exts=[".doc", ".xls", ".ppt", ".docx", ".xlsx", ".pptx", ".jpg", "vsd", "bmp"]
    5. def checkNeedsLock(repos, txn):
    6.     getfile_cmd = '%s changed -t "%s" "%s"' % (SVNLOOK, txn, repos)
    7.     getfile_res = os.popen(getfile_cmd, 'r').readlines()
    8.     for ln in getfile_res:
    9.         fname = ln[1:].strip()
    10.         ext = os.path.splitext(fname)[1].lower()
    11.         if ext in exts:
    12.             getprop_cmd = '%s propget -t "%s" "%s" svn:needs-lock "%s" ' % (SVNLOOK, txn, repos, fname)
    13.             getprop_res = os.popen(getprop_cmd, 'r').read().strip()
    14.             if getprop_res != "*":
    15.                 sys.stderr.write (ext + " file must have the needs-lock property. Please check you client configuration./n")
    16.                 sys.exit(1)
    17. def main(repos, txn):
    18.     checkNeedsLock(repos, txn)
    19.     exit(0)
    20. if __name__ == '__main__':
    21.     if len(sys.argv) < 3:
    22.         sys.stderr.write("Usage: %s REPOS TXN/n" % (sys.argv[0]))
    23.         exit(1)
    24.     else:
    25.         main(sys.argv[1], sys.argv[2])
    import sys, os, stringimport time SVNLOOK='svnlook.exe'exts=[".doc", ".xls", ".ppt", ".docx", ".xlsx", ".pptx", ".jpg", "vsd", "bmp"]def checkNeedsLock(repos, txn): getfile_cmd = '%s changed -t "%s" "%s"' % (SVNLOOK, txn, repos) getfile_res = os.popen(getfile_cmd, 'r').readlines() for ln in getfile_res: fname = ln[1:].strip() ext = os.path.splitext(fname)[1].lower() if ext in exts: getprop_cmd = '%s propget -t "%s" "%s" svn:needs-lock "%s" ' % (SVNLOOK, txn, repos, fname) getprop_res = os.popen(getprop_cmd, 'r').read().strip() if getprop_res != "*": sys.stderr.write (ext + " file must have the needs-lock property. Please check you client configuration./n") sys.exit(1) def main(repos, txn): checkNeedsLock(repos, txn) exit(0)if __name__ == '__main__': if len(sys.argv) < 3: sys.stderr.write("Usage: %s REPOS TXN/n" % (sys.argv[0])) exit(1) else: main(sys.argv[1], sys.argv[2])  习惯用python做了。 如果有人想要bat,可以参考这个 http://www.nabble.com/using-pre-commit-hook-to-check-for-a-property-td15551677.html *.xls = svn:mime-type=application/vnd.ms-excel;svn:needs-lock=* *.zip = svn:mime-type=application/zip;svn:needs-lock=*
  • 相关阅读:
    每日一练ACM 2019.0417
    每日一练ACM 2019.0416
    每日一练ACM 2019.04.13
    每日一练ACM 2019.04.14
    创建线程的方法
    类和对象的概念
    接口的概念
    Mysql添加取消自增属性
    SpringMVC不支持PUT表单提交
    SSM框架整合报org.springframework.beans.factory.NoSuchBeanDefinitionException
  • 原文地址:https://www.cnblogs.com/adodo1/p/4328038.html
Copyright © 2020-2023  润新知