[PATCH 1 of 3 V4] chg: implement validate in hgclient
Jun Wu
quark at fb.com
Sun Mar 6 13:26:58 UTC 2016
# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1457185617 0
# Sat Mar 05 13:46:57 2016 +0000
# Node ID 64fc0ca8f5d7df4dfb133817708fcafb53f6b89f
# Parent 897a4bbd578b1f97e12a5fe9d5a1f6d280496bb8
chg: implement validate in hgclient
This patch implements the corresponding validate method in hgclient.
It will return instruction strings as is without taking any real action.
diff --git a/contrib/chg/hgclient.c b/contrib/chg/hgclient.c
--- a/contrib/chg/hgclient.c
+++ b/contrib/chg/hgclient.c
@@ -34,6 +34,7 @@
CAP_GETPAGER = 0x0400,
CAP_SETENV = 0x0800,
CAP_SETUMASK = 0x1000,
+ CAP_VALIDATE = 0x2000,
};
typedef struct {
@@ -49,6 +50,7 @@
{"getpager", CAP_GETPAGER},
{"setenv", CAP_SETENV},
{"setumask", CAP_SETUMASK},
+ {"validate", CAP_VALIDATE},
{NULL, 0}, /* terminator */
};
@@ -463,6 +465,49 @@
}
/*!
+ * Send command line arguments to let the server load the repo config and check
+ * whether it can process our request directly or not.
+ * Make sure hgc_setenv is called before calling this.
+ *
+ * @return - NULL, the server believes it can handle our request, or does not
+ * support "validate" command.
+ * - a list of strings, the server cannot handle our request and it
+ * sent instructions telling us how to fix the issue. See
+ * chgserver.py for possible instruction formats.
+ * the last string is guaranteed to be NULL.
+ */
+const char **hgc_validate(hgclient_t *hgc, const char *const args[],
+ size_t argsize)
+{
+ assert(hgc);
+ if (!(hgc->capflags & CAP_VALIDATE))
+ return NULL;
+
+ packcmdargs(&hgc->ctx, args, argsize);
+ writeblockrequest(hgc, "validate");
+ readchannel(hgc);
+
+ /* the server returns '\0' if it can handle our request */
+ if (hgc->ctx.datasize <= 1)
+ return NULL;
+
+ /* make sure the buffer is '\0' terminated */
+ enlargecontext(&hgc->ctx, hgc->ctx.datasize + 1);
+ hgc->ctx.data[hgc->ctx.datasize] = '\0';
+
+ /* parse instruction list */
+ const char **buf = unpackcmdargsnul(&hgc->ctx);
+ const char **end;
+ for (end = buf; *end; ++end);
+ size_t bytes = (end - buf + 1) * sizeof(char **);
+ enlargecontext(&hgc->ctx, hgc->ctx.datasize + 1 + bytes);
+ end = (const char **)&hgc->ctx.data[hgc->ctx.datasize + 1];
+ memcpy(end, buf, bytes);
+ free(buf);
+ return end;
+}
+
+/*!
* Execute the specified Mercurial command
*
* @return result code
diff --git a/contrib/chg/hgclient.h b/contrib/chg/hgclient.h
--- a/contrib/chg/hgclient.h
+++ b/contrib/chg/hgclient.h
@@ -25,5 +25,7 @@
const char *hgc_getpager(hgclient_t *hgc, const char *const args[],
size_t argsize);
void hgc_setenv(hgclient_t *hgc, const char *const envp[]);
+const char **hgc_validate(hgclient_t *hgc, const char *const args[],
+ size_t argsize);
#endif /* HGCLIENT_H_ */
More information about the Mercurial-devel
mailing list