comparison contrib/chg/hgclient.c @ 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 c6e0c2533e5f
children b957b4c6cad8
comparison
equal deleted inserted replaced
28355:897a4bbd578b 28356:a5c773acb018
32 CAP_ATTACHIO = 0x0100, 32 CAP_ATTACHIO = 0x0100,
33 CAP_CHDIR = 0x0200, 33 CAP_CHDIR = 0x0200,
34 CAP_GETPAGER = 0x0400, 34 CAP_GETPAGER = 0x0400,
35 CAP_SETENV = 0x0800, 35 CAP_SETENV = 0x0800,
36 CAP_SETUMASK = 0x1000, 36 CAP_SETUMASK = 0x1000,
37 CAP_VALIDATE = 0x2000,
37 }; 38 };
38 39
39 typedef struct { 40 typedef struct {
40 const char *name; 41 const char *name;
41 unsigned int flag; 42 unsigned int flag;
47 {"attachio", CAP_ATTACHIO}, 48 {"attachio", CAP_ATTACHIO},
48 {"chdir", CAP_CHDIR}, 49 {"chdir", CAP_CHDIR},
49 {"getpager", CAP_GETPAGER}, 50 {"getpager", CAP_GETPAGER},
50 {"setenv", CAP_SETENV}, 51 {"setenv", CAP_SETENV},
51 {"setumask", CAP_SETUMASK}, 52 {"setumask", CAP_SETUMASK},
53 {"validate", CAP_VALIDATE},
52 {NULL, 0}, /* terminator */ 54 {NULL, 0}, /* terminator */
53 }; 55 };
54 56
55 typedef struct { 57 typedef struct {
56 char ch; 58 char ch;
461 assert(hgc); 463 assert(hgc);
462 return hgc->pid; 464 return hgc->pid;
463 } 465 }
464 466
465 /*! 467 /*!
468 * Send command line arguments to let the server load the repo config and check
469 * whether it can process our request directly or not.
470 * Make sure hgc_setenv is called before calling this.
471 *
472 * @return - NULL, the server believes it can handle our request, or does not
473 * support "validate" command.
474 * - a list of strings, the server cannot handle our request and it
475 * sent instructions telling us how to fix the issue. See
476 * chgserver.py for possible instruction formats.
477 * the list should be freed by the caller.
478 * the last string is guaranteed to be NULL.
479 */
480 const char **hgc_validate(hgclient_t *hgc, const char *const args[],
481 size_t argsize)
482 {
483 assert(hgc);
484 if (!(hgc->capflags & CAP_VALIDATE))
485 return NULL;
486
487 packcmdargs(&hgc->ctx, args, argsize);
488 writeblockrequest(hgc, "validate");
489 handleresponse(hgc);
490
491 /* the server returns '\0' if it can handle our request */
492 if (hgc->ctx.datasize <= 1)
493 return NULL;
494
495 /* make sure the buffer is '\0' terminated */
496 enlargecontext(&hgc->ctx, hgc->ctx.datasize + 1);
497 hgc->ctx.data[hgc->ctx.datasize] = '\0';
498 return unpackcmdargsnul(&hgc->ctx);
499 }
500
501 /*!
466 * Execute the specified Mercurial command 502 * Execute the specified Mercurial command
467 * 503 *
468 * @return result code 504 * @return result code
469 */ 505 */
470 int hgc_runcommand(hgclient_t *hgc, const char *const args[], size_t argsize) 506 int hgc_runcommand(hgclient_t *hgc, const char *const args[], size_t argsize)