diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -123,6 +123,9 @@ def _runcatch(req): else: ui.warn(_("hg: %s\n") % inst.args[1]) commands.help_(ui, 'shortlist') + except error.OutOfBandError, inst: + ui.warn("abort: remote error:\n") + ui.warn(''.join(inst.args)) except error.RepoError, inst: ui.warn(_("abort: %s!\n") % inst) if inst.hint: diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -39,6 +39,9 @@ class Abort(Exception): class ConfigError(Abort): 'Exception raised when parsing config files' +class OutOfBandError(Exception): + 'Exception raised when a remote repo reports failure' + class ParseError(Exception): 'Exception raised when parsing config files (msg[, pos])' diff --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py --- a/mercurial/hgweb/protocol.py +++ b/mercurial/hgweb/protocol.py @@ -10,6 +10,7 @@ from mercurial import util, wireproto from common import HTTP_OK HGTYPE = 'application/mercurial-0.1' +HGERRTYPE = 'application/hg-error' class webproto(object): def __init__(self, req, ui): @@ -90,3 +91,7 @@ def call(repo, req, cmd): rsp = '0\n%s\n' % rsp.res req.respond(HTTP_OK, HGTYPE, length=len(rsp)) return [rsp] + elif isinstance(rsp, wireproto.ooberror): + rsp = rsp.message + req.respond(HTTP_OK, HGERRTYPE, length=len(rsp)) + return [rsp] diff --git a/mercurial/httprepo.py b/mercurial/httprepo.py --- a/mercurial/httprepo.py +++ b/mercurial/httprepo.py @@ -136,6 +136,8 @@ class httprepository(wireproto.wirerepos proto = resp.headers.get('content-type', '') safeurl = util.hidepassword(self._url) + if proto.startswith('application/hg-error'): + raise error.OutOfBandError(resp.read()) # accept old "text/plain" and "application/hg-changegroup" for now if not (proto.startswith('application/mercurial-') or proto.startswith('text/plain') or diff --git a/mercurial/sshrepo.py b/mercurial/sshrepo.py --- a/mercurial/sshrepo.py +++ b/mercurial/sshrepo.py @@ -164,6 +164,17 @@ class sshrepository(wireproto.wirereposi def _recv(self): l = self.pipei.readline() + if l == '\n': + err = [] + while True: + line = self.pipee.readline() + if line == '-\n': + break + err.extend([line]) + if len(err) > 0: + # strip the trailing newline added to the last line server-side + err[-1] = err[-1][:-1] + self._abort(error.OutOfBandError(*err)) self.readerr() try: l = int(l) diff --git a/mercurial/sshserver.py b/mercurial/sshserver.py --- a/mercurial/sshserver.py +++ b/mercurial/sshserver.py @@ -82,6 +82,12 @@ class sshserver(object): def sendpusherror(self, rsp): self.sendresponse(rsp.res) + def sendooberror(self, rsp): + self.ui.ferr.write('%s\n-\n' % rsp.message) + self.ui.ferr.flush() + self.fout.write('\n') + self.fout.flush() + def serve_forever(self): try: while self.serve_one(): @@ -96,6 +102,7 @@ class sshserver(object): wireproto.streamres: sendstream, wireproto.pushres: sendpushresponse, wireproto.pusherr: sendpusherror, + wireproto.ooberror: sendooberror, } def serve_one(self): diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py --- a/mercurial/wireproto.py +++ b/mercurial/wireproto.py @@ -335,6 +335,10 @@ class pusherr(object): def __init__(self, res): self.res = res +class ooberror(object): + def __init__(self, message): + self.message = message + def dispatch(repo, proto, command): func, spec = commands[command] args = proto.getargs(spec) @@ -376,6 +380,8 @@ def batch(repo, proto, cmds, others): result = func(repo, proto, *[data[k] for k in keys]) else: result = func(repo, proto) + if isinstance(result, ooberror): + return result res.append(escapearg(result)) return ';'.join(res)