Mercurial > hg
changeset 28356:a5c773acb018
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.
author | Jun Wu <quark@fb.com> |
---|---|
date | Sun, 06 Mar 2016 14:21:52 +0000 |
parents | 897a4bbd578b |
children | 2f0f352d4196 |
files | contrib/chg/hgclient.c contrib/chg/hgclient.h |
diffstat | 2 files changed, 38 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/chg/hgclient.c Sun Mar 06 03:15:45 2016 +0530 +++ b/contrib/chg/hgclient.c Sun Mar 06 14:21:52 2016 +0000 @@ -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,40 @@ } /*! + * 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 list should be freed by the caller. + * 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"); + handleresponse(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'; + return unpackcmdargsnul(&hgc->ctx); +} + +/*! * Execute the specified Mercurial command * * @return result code
--- a/contrib/chg/hgclient.h Sun Mar 06 03:15:45 2016 +0530 +++ b/contrib/chg/hgclient.h Sun Mar 06 14:21:52 2016 +0000 @@ -20,6 +20,8 @@ pid_t hgc_peerpid(const hgclient_t *hgc); +const char **hgc_validate(hgclient_t *hgc, const char *const args[], + size_t argsize); int hgc_runcommand(hgclient_t *hgc, const char *const args[], size_t argsize); void hgc_attachio(hgclient_t *hgc); const char *hgc_getpager(hgclient_t *hgc, const char *const args[],