Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hook.py @ 38074:242eb5132203
filemerge: support specifying a python function to custom merge-tools
Eliminates the need to specify a python executable, which may not exist on
system. Additionally launching script inprocess aids portability on systems
that can't execute python via the shell.
Example usage "merge-tools.myTool.executable=python:c:\myTool.py:mergefn"
where myTool.py contains a function:
"def mergefn(ui, repo, args, **kwargs):"
where args is list of args passed to merge tool.
(by default, expanded: $local $base $other)
Invoking the specified python function was done by exposing and invoking
(hook._pythonhook -> hook.pythonhook)
author | hindlemail <tom_hindle@sil.org> |
---|---|
date | Wed, 16 May 2018 14:11:41 -0600 |
parents | 32bc3815efae |
children | e9e61fbac787 |
comparison
equal
deleted
inserted
replaced
38073:37ef6ee87488 | 38074:242eb5132203 |
---|---|
22 from .utils import ( | 22 from .utils import ( |
23 procutil, | 23 procutil, |
24 stringutil, | 24 stringutil, |
25 ) | 25 ) |
26 | 26 |
27 def _pythonhook(ui, repo, htype, hname, funcname, args, throw): | 27 def pythonhook(ui, repo, htype, hname, funcname, args, throw): |
28 '''call python hook. hook is callable object, looked up as | 28 '''call python hook. hook is callable object, looked up as |
29 name in python module. if callable returns "true", hook | 29 name in python module. if callable returns "true", hook |
30 fails, else passes. if hook raises exception, treated as | 30 fails, else passes. if hook raises exception, treated as |
31 hook failure. exception propagates if throw is "true". | 31 hook failure. exception propagates if throw is "true". |
32 | 32 |
240 hint = _("see 'hg help config.trusted'")) | 240 hint = _("see 'hg help config.trusted'")) |
241 ui.warn(_('warning: untrusted hook %s not executed\n') % hname) | 241 ui.warn(_('warning: untrusted hook %s not executed\n') % hname) |
242 r = 1 | 242 r = 1 |
243 raised = False | 243 raised = False |
244 elif callable(cmd): | 244 elif callable(cmd): |
245 r, raised = _pythonhook(ui, repo, htype, hname, cmd, args, | 245 r, raised = pythonhook(ui, repo, htype, hname, cmd, args, |
246 throw) | 246 throw) |
247 elif cmd.startswith('python:'): | 247 elif cmd.startswith('python:'): |
248 if cmd.count(':') >= 2: | 248 if cmd.count(':') >= 2: |
249 path, cmd = cmd[7:].rsplit(':', 1) | 249 path, cmd = cmd[7:].rsplit(':', 1) |
250 path = util.expandpath(path) | 250 path = util.expandpath(path) |
256 ui.write(_("loading %s hook failed:\n") % hname) | 256 ui.write(_("loading %s hook failed:\n") % hname) |
257 raise | 257 raise |
258 hookfn = getattr(mod, cmd) | 258 hookfn = getattr(mod, cmd) |
259 else: | 259 else: |
260 hookfn = cmd[7:].strip() | 260 hookfn = cmd[7:].strip() |
261 r, raised = _pythonhook(ui, repo, htype, hname, hookfn, args, | 261 r, raised = pythonhook(ui, repo, htype, hname, hookfn, args, |
262 throw) | 262 throw) |
263 else: | 263 else: |
264 r = _exthook(ui, repo, htype, hname, cmd, args, throw) | 264 r = _exthook(ui, repo, htype, hname, cmd, args, throw) |
265 raised = False | 265 raised = False |
266 | 266 |