[PATCH 2 of 4 V3] chg: implement validate in hgclient

Yuya Nishihara yuya at tcha.org
Sun Mar 6 11:07:57 UTC 2016


On Sat, 5 Mar 2016 14:00:11 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1457185617 0
> #      Sat Mar 05 13:46:57 2016 +0000
> # Node ID cb345048855bb8e47ca28a13388fb3291e7aee2e
> # Parent  f9ac561d5843234187751a508b6d557e8903ceac
> chg: implement validate in hgclient

> +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';
> +
> +	/* 2 instructions at most (unlink + redirect), +1 for NULL */
> +	static const char *insts[3];

Using static buffer seems wrong because theoretically an hgclient object can
be created more than once.

I found unpackcmdargsnul() do the same job. Perhaps we can use it if we take
the original free-by-caller design. Though it won't be nice to expose an
internally-allocated buffer, it will be simple as there is the function.

I should remember I wrote it last year, sorry.


More information about the Mercurial-devel mailing list