Mercurial > hg
changeset 1884:4e44ca05a866
merge with self.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Fri, 10 Mar 2006 23:34:36 -0800 |
parents | b98160cfb2f3 (diff) 4392ccefe432 (current diff) |
children | c4d577262d00 |
files | hgmerge |
diffstat | 4 files changed, 39 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/hgmerge Fri Mar 10 23:25:50 2006 -0800 +++ b/hgmerge Fri Mar 10 23:34:36 2006 -0800 @@ -4,6 +4,12 @@ # # This tries to find a way to do three-way merge on the current system. # The result ought to end up in $1. +# +# Environment variables set by Mercurial: +# HG_ROOT repo root +# HG_FILE name of file within repo +# HG_MY_NODE revision being merged +# HG_OTHER_NODE revision being merged set -e # bail out quickly on failure
--- a/mercurial/localrepo.py Fri Mar 10 23:25:50 2006 -0800 +++ b/mercurial/localrepo.py Fri Mar 10 23:34:36 2006 -0800 @@ -55,7 +55,7 @@ def runhook(name, cmd): self.ui.note(_("running hook %s: %s\n") % (name, cmd)) env = dict([('HG_' + k.upper(), v) for k, v in args.iteritems()]) - r = util.esystem(cmd, environ=env, cwd=self.root) + r = util.system(cmd, environ=env, cwd=self.root) if r: desc, r = util.explain_exit(r) if throw: @@ -1636,10 +1636,12 @@ # merge the tricky bits files = merge.keys() files.sort() + xp1 = hex(p1) + xp2 = hex(p2) for f in files: self.ui.status(_("merging %s\n") % f) my, other, flag = merge[f] - ret = self.merge3(f, my, other) + ret = self.merge3(f, my, other, xp1, xp2) if ret: err = True util.set_exec(self.wjoin(f), flag) @@ -1677,7 +1679,7 @@ self.dirstate.setparents(p1, p2) return err - def merge3(self, fn, my, other): + def merge3(self, fn, my, other, p1, p2): """perform a 3-way merge in the working directory""" def temp(prefix, node): @@ -1700,7 +1702,14 @@ cmd = (os.environ.get("HGMERGE") or self.ui.config("ui", "merge") or "hgmerge") - r = os.system('%s "%s" "%s" "%s"' % (cmd, a, b, c)) + r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), + environ={'HG_ROOT': self.root, + 'HG_FILE': fn, + 'HG_MY_NODE': p1, + 'HG_OTHER_NODE': p2, + 'HG_FILE_MY_NODE': hex(my), + 'HG_FILE_OTHER_NODE': hex(other), + 'HG_FILE_BASE_NODE': hex(base)}) if r: self.ui.warn(_("merging %s failed!\n") % fn)
--- a/mercurial/ui.py Fri Mar 10 23:25:50 2006 -0800 +++ b/mercurial/ui.py Fri Mar 10 23:34:36 2006 -0800 @@ -209,7 +209,9 @@ os.environ.get("EDITOR", "vi")) os.environ["HGUSER"] = self.username() - util.system("%s \"%s\"" % (editor, name), errprefix=_("edit failed")) + util.system("%s \"%s\"" % (editor, name), + environ={'HGUSER': self.username()}, + onerr=util.Abort, errprefix=_("edit failed")) t = open(name).read() t = re.sub("(?m)^HG:.*\n", "", t)
--- a/mercurial/util.py Fri Mar 10 23:25:50 2006 -0800 +++ b/mercurial/util.py Fri Mar 10 23:34:36 2006 -0800 @@ -315,19 +315,13 @@ (files and filematch(fn)))), (inc or exc or (pats and pats != [('glob', '**')])) and True) -def system(cmd, errprefix=None): - """execute a shell command that must succeed""" - rc = os.system(cmd) - if rc: - errmsg = "%s %s" % (os.path.basename(cmd.split(None, 1)[0]), - explain_exit(rc)[0]) - if errprefix: - errmsg = "%s: %s" % (errprefix, errmsg) - raise Abort(errmsg) +def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None): + '''enhanced shell command execution. + run with environment maybe modified, maybe in different dir. -def esystem(cmd, environ={}, cwd=None): - '''enhanced shell command execution. - run with environment maybe modified, maybe in different dir.''' + if command fails and onerr is None, return status. if ui object, + print error message and return status, else raise onerr object as + exception.''' oldenv = {} for k in environ: oldenv[k] = os.environ.get(k) @@ -338,7 +332,17 @@ os.environ[k] = str(v) if cwd is not None and oldcwd != cwd: os.chdir(cwd) - return os.system(cmd) + rc = os.system(cmd) + if rc and onerr: + errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]), + explain_exit(rc)[0]) + if errprefix: + errmsg = '%s: %s' % (errprefix, errmsg) + try: + onerr.warn(errmsg + '\n') + except AttributeError: + raise onerr(errmsg) + return rc finally: for k, v in oldenv.iteritems(): if v is None: