##// END OF EJS Templates
Handle functions as the value of a hooks.<name> config variable...
Alexis S. L. Carvalho -
r4070:961ccb61 default
parent child Browse files
Show More
@@ -142,10 +142,12 b' class localrepository(repo.repository):'
142 be run as hooks without wrappers to convert return values.'''
142 be run as hooks without wrappers to convert return values.'''
143
143
144 self.ui.note(_("calling hook %s: %s\n") % (hname, funcname))
144 self.ui.note(_("calling hook %s: %s\n") % (hname, funcname))
145 obj = funcname
146 if not callable(obj):
145 d = funcname.rfind('.')
147 d = funcname.rfind('.')
146 if d == -1:
148 if d == -1:
147 raise util.Abort(_('%s hook is invalid ("%s" not in a module)')
149 raise util.Abort(_('%s hook is invalid ("%s" not in '
148 % (hname, funcname))
150 'a module)') % (hname, funcname))
149 modname = funcname[:d]
151 modname = funcname[:d]
150 try:
152 try:
151 obj = __import__(modname)
153 obj = __import__(modname)
@@ -205,7 +207,9 b' class localrepository(repo.repository):'
205 if hname.split(".", 1)[0] == name and cmd]
207 if hname.split(".", 1)[0] == name and cmd]
206 hooks.sort()
208 hooks.sort()
207 for hname, cmd in hooks:
209 for hname, cmd in hooks:
208 if cmd.startswith('python:'):
210 if callable(cmd):
211 r = callhook(hname, cmd) or r
212 elif cmd.startswith('python:'):
209 r = callhook(hname, cmd[7:].strip()) or r
213 r = callhook(hname, cmd[7:].strip()) or r
210 else:
214 else:
211 r = runhook(hname, cmd) or r
215 r = runhook(hname, cmd) or r
@@ -183,4 +183,24 b" echo 'commit.abort = python:hooktests.ab"
183 echo a >> a
183 echo a >> a
184 hg --traceback commit -A -m a 2>&1 | grep '^Traceback'
184 hg --traceback commit -A -m a 2>&1 | grep '^Traceback'
185
185
186 cd ..
187 hg init c
188 cd c
189
190 cat > hookext.py <<EOF
191 def autohook(**args):
192 print "Automatically installed hook"
193
194 def reposetup(ui, repo):
195 repo.ui.setconfig("hooks", "commit.auto", autohook)
196 EOF
197 echo '[extensions]' >> .hg/hgrc
198 echo 'hookext = hookext.py' >> .hg/hgrc
199
200 touch foo
201 hg add foo
202 hg ci -m 'add foo'
203 echo >> foo
204 hg ci --debug -m 'change foo' | sed -e 's/ at .*>/>/'
205
186 exit 0
206 exit 0
@@ -138,3 +138,7 b' added 1 changesets with 1 changes to 1 f'
138 (run 'hg update' to get a working copy)
138 (run 'hg update' to get a working copy)
139 # make sure --traceback works
139 # make sure --traceback works
140 Traceback (most recent call last):
140 Traceback (most recent call last):
141 Automatically installed hook
142 foo
143 calling hook commit.auto: <function autohook>
144 Automatically installed hook
General Comments 0
You need to be logged in to leave comments. Login now