[PATCH 2 of 2] chg: provide early exception to user

Yuya Nishihara yuya at tcha.org
Sat Mar 12 09:01:12 EST 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1457788650 -32400
#      Sat Mar 12 22:17:30 2016 +0900
# Node ID ac410dea1b240854b5f0c99dddde66c5b19f6d36
# Parent  44c2880005610595f4a098dfc74672a68b93c147
chg: provide early exception to user

See the previous patch for details. Since the socket will be closed by the
server, handleresponse() will never return:

  Traceback (most recent call last):
    ...
  chg: abort: failed to read channel

diff --git a/contrib/chg/hgclient.c b/contrib/chg/hgclient.c
--- a/contrib/chg/hgclient.c
+++ b/contrib/chg/hgclient.c
@@ -311,9 +311,16 @@ static void readhello(hgclient_t *hgc)
 {
 	readchannel(hgc);
 	context_t *ctx = &hgc->ctx;
-	if (ctx->ch != 'o')
-		abortmsg("unexpected channel of hello message (ch = %c)",
-			 ctx->ch);
+	if (ctx->ch != 'o') {
+		char ch = ctx->ch;
+		if (ch == 'e') {
+			/* write early error and will exit */
+			fwrite(ctx->data, sizeof(ctx->data[0]), ctx->datasize,
+			       stderr);
+			handleresponse(hgc);
+		}
+		abortmsg("unexpected channel of hello message (ch = %c)", ch);
+	}
 	enlargecontext(ctx, ctx->datasize + 1);
 	ctx->data[ctx->datasize] = '\0';
 	debugmsg("hello received: %s (size = %zu)", ctx->data, ctx->datasize);


More information about the Mercurial-devel mailing list