Quantcast
WoWInterface: SVN - Blessed - Blame - Rev 3 - /hooks/pre-lock.tmpl

WoWInterface SVN Blessed

[/] [hooks/] [pre-lock.tmpl] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 Ailae-78500
#!/bin/sh
2 Ailae-78500
 
3 Ailae-78500
# PRE-LOCK HOOK
4 Ailae-78500
#
5 Ailae-78500
# The pre-lock hook is invoked before an exclusive lock is
6 Ailae-78500
# created.  Subversion runs this hook by invoking a program
7 Ailae-78500
# (script, executable, binary, etc.) named 'pre-lock' (for which
8 Ailae-78500
# this file is a template), with the following ordered arguments:
9 Ailae-78500
#
10 Ailae-78500
#   [1] REPOS-PATH   (the path to this repository)
11 Ailae-78500
#   [2] PATH         (the path in the repository about to be locked)
12 Ailae-78500
#   [3] USER         (the user creating the lock)
13 Ailae-78500
#   [4] COMMENT      (the comment of the lock)
14 Ailae-78500
#   [5] STEAL-LOCK   (1 if the user is trying to steal the lock, else 0)
15 Ailae-78500
#
16 Ailae-78500
# If the hook program outputs anything on stdout, the output string will
17 Ailae-78500
# be used as the lock token for this lock operation.  If you choose to use
18 Ailae-78500
# this feature, you must guarantee the tokens generated are unique across
19 Ailae-78500
# the repository each time.
20 Ailae-78500
#
21 Ailae-78500
# The default working directory for the invocation is undefined, so
22 Ailae-78500
# the program should set one explicitly if it cares.
23 Ailae-78500
#
24 Ailae-78500
# If the hook program exits with success, the lock is created; but
25 Ailae-78500
# if it exits with failure (non-zero), the lock action is aborted
26 Ailae-78500
# and STDERR is returned to the client.
27 Ailae-78500
 
28 Ailae-78500
# On a Unix system, the normal procedure is to have 'pre-lock'
29 Ailae-78500
# invoke other programs to do the real work, though it may do the
30 Ailae-78500
# work itself too.
31 Ailae-78500
#
32 Ailae-78500
# Note that 'pre-lock' must be executable by the user(s) who will
33 Ailae-78500
# invoke it (typically the user httpd runs as), and that user must
34 Ailae-78500
# have filesystem-level permission to access the repository.
35 Ailae-78500
#
36 Ailae-78500
# On a Windows system, you should name the hook program
37 Ailae-78500
# 'pre-lock.bat' or 'pre-lock.exe',
38 Ailae-78500
# but the basic idea is the same.
39 Ailae-78500
#
40 Ailae-78500
# Here is an example hook script, for a Unix /bin/sh interpreter:
41 Ailae-78500
 
42 Ailae-78500
REPOS="$1"
43 Ailae-78500
PATH="$2"
44 Ailae-78500
USER="$3"
45 Ailae-78500
 
46 Ailae-78500
# If a lock exists and is owned by a different person, don't allow it
47 Ailae-78500
# to be stolen (e.g., with 'svn lock --force ...').
48 Ailae-78500
 
49 Ailae-78500
# (Maybe this script could send email to the lock owner?)
50 Ailae-78500
SVNLOOK=/usr/local/bin/svnlook
51 Ailae-78500
GREP=/bin/grep
52 Ailae-78500
SED=/bin/sed
53 Ailae-78500
 
54 Ailae-78500
LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \
55 Ailae-78500
            $GREP '^Owner: ' | $SED 's/Owner: //'`
56 Ailae-78500
 
57 Ailae-78500
# If we get no result from svnlook, there's no lock, allow the lock to
58 Ailae-78500
# happen:
59 Ailae-78500
if [ "$LOCK_OWNER" = "" ]; then
60 Ailae-78500
  exit 0
61 Ailae-78500
fi
62 Ailae-78500
 
63 Ailae-78500
# If the person locking matches the lock's owner, allow the lock to
64 Ailae-78500
# happen:
65 Ailae-78500
if [ "$LOCK_OWNER" = "$USER" ]; then
66 Ailae-78500
  exit 0
67 Ailae-78500
fi
68 Ailae-78500
 
69 Ailae-78500
# Otherwise, we've got an owner mismatch, so return failure:
70 Ailae-78500
echo "Error: $PATH already locked by ${LOCK_OWNER}." 1>&2
71 Ailae-78500
exit 1