Show More
@@ -55,7 +55,7 b' class localrepository(object):' | |||
|
55 | 55 | def runhook(name, cmd): |
|
56 | 56 | self.ui.note(_("running hook %s: %s\n") % (name, cmd)) |
|
57 | 57 | env = dict([('HG_' + k.upper(), v) for k, v in args.iteritems()]) |
|
58 |
r = util. |
|
|
58 | r = util.system(cmd, environ=env, cwd=self.root) | |
|
59 | 59 | if r: |
|
60 | 60 | desc, r = util.explain_exit(r) |
|
61 | 61 | if throw: |
@@ -209,7 +209,9 b' class ui(object):' | |||
|
209 | 209 | os.environ.get("EDITOR", "vi")) |
|
210 | 210 | |
|
211 | 211 | os.environ["HGUSER"] = self.username() |
|
212 |
util.system("%s \"%s\"" % (editor, name), |
|
|
212 | util.system("%s \"%s\"" % (editor, name), | |
|
213 | environ={'HGUSER': self.username()}, | |
|
214 | onerr=util.Abort, errprefix=_("edit failed")) | |
|
213 | 215 | |
|
214 | 216 | t = open(name).read() |
|
215 | 217 | t = re.sub("(?m)^HG:.*\n", "", t) |
@@ -315,19 +315,13 b' def _matcher(canonroot, cwd, names, inc,' | |||
|
315 | 315 | (files and filematch(fn)))), |
|
316 | 316 | (inc or exc or (pats and pats != [('glob', '**')])) and True) |
|
317 | 317 | |
|
318 | def system(cmd, errprefix=None): | |
|
319 | """execute a shell command that must succeed""" | |
|
320 | rc = os.system(cmd) | |
|
321 | if rc: | |
|
322 | errmsg = "%s %s" % (os.path.basename(cmd.split(None, 1)[0]), | |
|
323 | explain_exit(rc)[0]) | |
|
324 | if errprefix: | |
|
325 | errmsg = "%s: %s" % (errprefix, errmsg) | |
|
326 | raise Abort(errmsg) | |
|
318 | def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None): | |
|
319 | '''enhanced shell command execution. | |
|
320 | run with environment maybe modified, maybe in different dir. | |
|
327 | 321 |
|
|
328 | def esystem(cmd, environ={}, cwd=None): | |
|
329 | '''enhanced shell command execution. | |
|
330 | run with environment maybe modified, maybe in different dir.''' | |
|
322 | if command fails and onerr is None, return status. if ui object, | |
|
323 | print error message and return status, else raise onerr object as | |
|
324 | exception.''' | |
|
331 | 325 | oldenv = {} |
|
332 | 326 | for k in environ: |
|
333 | 327 | oldenv[k] = os.environ.get(k) |
@@ -338,7 +332,17 b' def esystem(cmd, environ={}, cwd=None):' | |||
|
338 | 332 | os.environ[k] = str(v) |
|
339 | 333 | if cwd is not None and oldcwd != cwd: |
|
340 | 334 | os.chdir(cwd) |
|
341 |
r |
|
|
335 | rc = os.system(cmd) | |
|
336 | if rc and onerr: | |
|
337 | errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]), | |
|
338 | explain_exit(rc)[0]) | |
|
339 | if errprefix: | |
|
340 | errmsg = '%s: %s' % (errprefix, errmsg) | |
|
341 | try: | |
|
342 | onerr.warn(errmsg + '\n') | |
|
343 | except AttributeError: | |
|
344 | raise onerr(errmsg) | |
|
345 | return rc | |
|
342 | 346 | finally: |
|
343 | 347 | for k, v in oldenv.iteritems(): |
|
344 | 348 | if v is None: |
General Comments 0
You need to be logged in to leave comments.
Login now