D). About "steal lock"

Source: Internet
Author: User

Http://developer.51cto.com/art/201108/282082.htm

This option was originally intended to increase flexibility. When a file is locked by others, you can still use the "steal" method to forcibly take the lock. However, this is also causedCodeOne of the potential causes of the conflict, we decided to avoid it. The technology used here is the hook script. Hook script is actually some script files, and some bat scripts in windows. Whenever SVN performs some specific operations, such as "locked" and "submitted", it searches for the relevant hook script in the specified directory and executes it to pre-process the corresponding commands. We need to check whether "steal lock" is checked when the user applies to lock the file before locking. If this option is selected, the operation is interrupted, prompting the user that this option has been disabled by the system. The directory for storing the hook script is related to the code library path. My directory is E: repositorieshwchhooks. After installation by default there are already a number of templates, with tmpl extension, for example, the pre-lock.tmpl is to lock the pre-operation done before, the post-commit.tmpl is done after the submission of the pre-operation. We create a new file in: pre-lock.bat, and then enter the following content in it:

 
 
  1. @ Echo off
  2.  
  3. Rem [1] REPOS-PATH (the path to this repository)
  4. Rem [2] path (the path in the repository about to be locked)
  5. Rem [3] user (the user creating the lock)
  6. Rem [4] Comment (the comment of the lock)
  7. Rem [5] STEAL-LOCK (1 if the user is trying to steal the lock, else 0)
  8.  
  9. Setlocal
  10. : SVN is sensitive to the path of the Code resource library and the right parentheses in the file path, which must be escaped.
  11. : Code resource library path
  12. SetRepos= % 1
  13. Set"Repos= % Repos :) = ^) %"
  14. : Current file path
  15. SetReppath= % 2
  16. Set"Reppath= % Reppath :) = ^) %"
  17. SetUsername= % 3
  18. SetIssteal= % 5
  19.  
  20. Rem no_stealing
  21. : If the instance is not locked, skip the link to finish processing.
  22. If/I '1' = '% issteal %' goto no_stealing
  23. Rem echo aaa>>D: \ log.txt
  24. Rem echoRepos= % Repos %>>D: \ log.txt
  25. Rem echoReppath= % Reppath %>>D: \ log.txt
  26. Rem echoUsername= % Username %>>D: \ log.txt
  27. Rem if the path has been locked, find the owner.
  28. : Here is the focus
  29. : Run svnlook lock % repos % reppath % to obtain the lock information, for example:
  30. : UUID token: opaquelocktoken: 1707b1a0-8dd1-a94e-87d2-6109a115cd5c
  31. : Owner: ljz
  32. : Created: August 20 21:05:31 + 0800 (Monday, 11)
  33. : Expires:
  34. : Comment (1 line ):
  35. : Use findstr/R/N "." To add a row number to the front of all rows, and then return all rows. For example:
  36. : 1: UUID token: opaquelocktoken: 1707b1a0-8dd1-a94e-87d2-6109a115cd5c
  37. : 2: Owner: ljz
  38. : 3: created: August 20 21:05:31 + 0800 (Monday, 11)
  39. : 4: expires:
  40. : 5: Comment (1 line ):
  41. : PassTokens=1, 2, 3Delims=:, With the separator ":" and "space", separate each line above and load the first three sections into the variables % I, % J, % K respectively.
  42. : If %I= 2 setLockedname= % K. The variable lockedname is loaded into the third segment after the second line is separated. Here, it is ljz.
  43. For/F"Tokens=1, 2, 3Delims=: "% I in ('svnlook lock % repos % reppath % ^ | findstr/R/N". "') Do (
  44. If %I= 2 setLockedname= % K
  45. )
  46.  
  47. Rem if we get no result from svnlook, there's no lock, allow the lock to happen.
  48. : If no lock information is obtained, skip to the end to process the lock.
  49. If not defined lockedname goto OK _exit
  50.  
  51. Rem if the person locking matches the lock's owner, allow the lock to happen.
  52. Rem but this one won't effect, the svn don't care if the person matchs, they just don't allow relock.
  53. Rem echoUsername= % Username %>>D: \ log.txt
  54. Rem echoLockedname= % Lockedname %>>D: \ log.txt
  55. : If the locked person has the same name as the current user, skip to the end of the process.
  56. If/I '% lockedname %' = '% username %' goto OK _exit
  57.  
  58. Rem otherwise, we 've got an owner mismatch, so return failure:
  59. : Wrong_person
  60. Echo the path has been locked by % lockedname %, pls contact % lockedname % to unlock it.>& 2
  61. Goto error_exit
  62. : No_stealing
  63. Echo stealing lock is not allowed at this server.>& 2
  64. : Error_exit
  65. Endlocal
  66. Exit 1
  67. : OK _exit
  68. Endlocal
  69. Exit 0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.