Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hook.py @ 38488:e9e61fbac787
hooks: allow Unix style environment variables on external Windows hooks
This will help making common hooks between Windows and non-Windows platforms.
Having to build the shellenviron dict here and in procutil.system() is a bit
unfortunate, but the only other option is to fix up the command inside
procutil.system(). It seems more important that the note about the hook being
run reflects what is actually run.
The patch from last summer added the hooks on the command line, but it looks
like HG_ARGS has since learned about --config args, and the output was just
confusing. Therefore, it's now loaded from a file in the histedit test for
clarity.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 02 Jul 2017 00:32:09 -0400 |
parents | 242eb5132203 |
children | 72286f9e324f |
comparison
equal
deleted
inserted
replaced
38487:3efadf2317c7 | 38488:e9e61fbac787 |
---|---|
118 raise error.HookAbort(_('%s hook failed') % hname) | 118 raise error.HookAbort(_('%s hook failed') % hname) |
119 ui.warn(_('warning: %s hook failed\n') % hname) | 119 ui.warn(_('warning: %s hook failed\n') % hname) |
120 return r, False | 120 return r, False |
121 | 121 |
122 def _exthook(ui, repo, htype, name, cmd, args, throw): | 122 def _exthook(ui, repo, htype, name, cmd, args, throw): |
123 ui.note(_("running hook %s: %s\n") % (name, cmd)) | |
124 | |
125 starttime = util.timer() | 123 starttime = util.timer() |
126 env = {} | 124 env = {} |
127 | 125 |
128 # make in-memory changes visible to external process | 126 # make in-memory changes visible to external process |
129 if repo is not None: | 127 if repo is not None: |
138 if callable(v): | 136 if callable(v): |
139 v = v() | 137 v = v() |
140 if isinstance(v, (dict, list)): | 138 if isinstance(v, (dict, list)): |
141 v = stringutil.pprint(v) | 139 v = stringutil.pprint(v) |
142 env['HG_' + k.upper()] = v | 140 env['HG_' + k.upper()] = v |
141 | |
142 if pycompat.iswindows: | |
143 environ = procutil.shellenviron(env) | |
144 cmd = util.platform.shelltocmdexe(cmd, environ) | |
145 | |
146 ui.note(_("running hook %s: %s\n") % (name, cmd)) | |
143 | 147 |
144 if repo: | 148 if repo: |
145 cwd = repo.root | 149 cwd = repo.root |
146 else: | 150 else: |
147 cwd = pycompat.getcwd() | 151 cwd = pycompat.getcwd() |