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:
-
- @ Echo off
-
-
-
- Rem [1] REPOS-PATH (the path to this repository)
- Rem [2] path (the path in the repository about to be locked)
-
- Rem [3] user (the user creating the lock)
-
- Rem [4] Comment (the comment of the lock)
-
- Rem [5] STEAL-LOCK (1 if the user is trying to steal the lock, else 0)
-
-
-
- Setlocal
-
- : SVN is sensitive to the path of the Code resource library and the right parentheses in the file path, which must be escaped.
-
- : Code resource library path
- SetRepos= % 1
-
- Set"Repos= % Repos :) = ^) %"
-
- : Current file path
-
- SetReppath= % 2
-
- Set"Reppath= % Reppath :) = ^) %"
-
- SetUsername= % 3
-
- SetIssteal= % 5
-
-
-
- Rem no_stealing
-
- : If the instance is not locked, skip the link to finish processing.
- If/I '1' = '% issteal %' goto no_stealing
-
- Rem echo aaa>>D: \ log.txt
-
- Rem echoRepos= % Repos %>>D: \ log.txt
-
- Rem echoReppath= % Reppath %>>D: \ log.txt
-
- Rem echoUsername= % Username %>>D: \ log.txt
- Rem if the path has been locked, find the owner.
-
- : Here is the focus
-
- : Run svnlook lock % repos % reppath % to obtain the lock information, for example:
-
- : UUID token: opaquelocktoken: 1707b1a0-8dd1-a94e-87d2-6109a115cd5c
-
- : Owner: ljz
-
- : Created: August 20 21:05:31 + 0800 (Monday, 11)
-
- : Expires:
-
- : Comment (1 line ):
-
- : Use findstr/R/N "." To add a row number to the front of all rows, and then return all rows. For example:
- : 1: UUID token: opaquelocktoken: 1707b1a0-8dd1-a94e-87d2-6109a115cd5c
-
- : 2: Owner: ljz
-
- : 3: created: August 20 21:05:31 + 0800 (Monday, 11)
-
- : 4: expires:
-
- : 5: Comment (1 line ):
-
- : 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.
- : If %I= 2 setLockedname= % K. The variable lockedname is loaded into the third segment after the second line is separated. Here, it is ljz.
-
- For/F"Tokens=1, 2, 3Delims=: "% I in ('svnlook lock % repos % reppath % ^ | findstr/R/N". "') Do (
-
- If %I= 2 setLockedname= % K
-
- )
-
-
- Rem if we get no result from svnlook, there's no lock, allow the lock to happen.
-
- : If no lock information is obtained, skip to the end to process the lock.
-
- If not defined lockedname goto OK _exit
-
-
-
- Rem if the person locking matches the lock's owner, allow the lock to happen.
-
- Rem but this one won't effect, the svn don't care if the person matchs, they just don't allow relock.
- Rem echoUsername= % Username %>>D: \ log.txt
-
- Rem echoLockedname= % Lockedname %>>D: \ log.txt
-
- : If the locked person has the same name as the current user, skip to the end of the process.
-
- If/I '% lockedname %' = '% username %' goto OK _exit
-
-
-
- Rem otherwise, we 've got an owner mismatch, so return failure:
-
- : Wrong_person
- Echo the path has been locked by % lockedname %, pls contact % lockedname % to unlock it.>& 2
-
- Goto error_exit
-
- : No_stealing
-
- Echo stealing lock is not allowed at this server.>& 2
-
- : Error_exit
-
- Endlocal
-
- Exit 1
-
- : OK _exit
-
- Endlocal
-
- Exit 0