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