Show More
@@ -142,32 +142,34 b' class localrepository(repo.repository):' | |||
|
142 | 142 | be run as hooks without wrappers to convert return values.''' |
|
143 | 143 | |
|
144 | 144 | self.ui.note(_("calling hook %s: %s\n") % (hname, funcname)) |
|
145 |
|
|
|
146 |
if |
|
|
147 | raise util.Abort(_('%s hook is invalid ("%s" not in a module)') | |
|
148 | % (hname, funcname)) | |
|
149 | modname = funcname[:d] | |
|
150 | try: | |
|
151 | obj = __import__(modname) | |
|
152 | except ImportError: | |
|
145 | obj = funcname | |
|
146 | if not callable(obj): | |
|
147 | d = funcname.rfind('.') | |
|
148 | if d == -1: | |
|
149 | raise util.Abort(_('%s hook is invalid ("%s" not in ' | |
|
150 | 'a module)') % (hname, funcname)) | |
|
151 | modname = funcname[:d] | |
|
153 | 152 | try: |
|
154 | # extensions are loaded with hgext_ prefix | |
|
155 | obj = __import__("hgext_%s" % modname) | |
|
153 | obj = __import__(modname) | |
|
156 | 154 | except ImportError: |
|
155 | try: | |
|
156 | # extensions are loaded with hgext_ prefix | |
|
157 | obj = __import__("hgext_%s" % modname) | |
|
158 | except ImportError: | |
|
159 | raise util.Abort(_('%s hook is invalid ' | |
|
160 | '(import of "%s" failed)') % | |
|
161 | (hname, modname)) | |
|
162 | try: | |
|
163 | for p in funcname.split('.')[1:]: | |
|
164 | obj = getattr(obj, p) | |
|
165 | except AttributeError, err: | |
|
157 | 166 | raise util.Abort(_('%s hook is invalid ' |
|
158 |
'( |
|
|
159 |
(hname, |
|
|
160 | try: | |
|
161 | for p in funcname.split('.')[1:]: | |
|
162 | obj = getattr(obj, p) | |
|
163 | except AttributeError, err: | |
|
164 | raise util.Abort(_('%s hook is invalid ' | |
|
165 | '("%s" is not defined)') % | |
|
166 | (hname, funcname)) | |
|
167 | if not callable(obj): | |
|
168 | raise util.Abort(_('%s hook is invalid ' | |
|
169 | '("%s" is not callable)') % | |
|
170 | (hname, funcname)) | |
|
167 | '("%s" is not defined)') % | |
|
168 | (hname, funcname)) | |
|
169 | if not callable(obj): | |
|
170 | raise util.Abort(_('%s hook is invalid ' | |
|
171 | '("%s" is not callable)') % | |
|
172 | (hname, funcname)) | |
|
171 | 173 | try: |
|
172 | 174 | r = obj(ui=self.ui, repo=self, hooktype=name, **args) |
|
173 | 175 | except (KeyboardInterrupt, util.SignalInterrupt): |
@@ -205,7 +207,9 b' class localrepository(repo.repository):' | |||
|
205 | 207 | if hname.split(".", 1)[0] == name and cmd] |
|
206 | 208 | hooks.sort() |
|
207 | 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 | 213 | r = callhook(hname, cmd[7:].strip()) or r |
|
210 | 214 | else: |
|
211 | 215 | r = runhook(hname, cmd) or r |
@@ -183,4 +183,24 b" echo 'commit.abort = python:hooktests.ab" | |||
|
183 | 183 | echo a >> a |
|
184 | 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 | 206 | exit 0 |
@@ -138,3 +138,7 b' added 1 changesets with 1 changes to 1 f' | |||
|
138 | 138 | (run 'hg update' to get a working copy) |
|
139 | 139 | # make sure --traceback works |
|
140 | 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