changeset 35998:9724f54923ec

chg: enable clang-format on all .c and .h files Nothing in here looks awful, so I think we may as well just do it. # skip-blame because it's just reformatting with no functionality change Differential Revision: https://phab.mercurial-scm.org/D2058
author Augie Fackler <augie@google.com>
date Tue, 06 Feb 2018 05:24:28 -0500
parents fd9f2a22ee83
children 580f7b1b88c7
files contrib/chg/chg.c contrib/chg/hgclient.c contrib/chg/hgclient.h contrib/chg/procutil.c contrib/chg/util.c contrib/chg/util.h contrib/clang-format-blacklist
diffstat 7 files changed, 83 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/chg/chg.c	Wed Feb 07 06:28:43 2018 -0500
+++ b/contrib/chg/chg.c	Tue Feb 06 05:24:28 2018 -0500
@@ -38,11 +38,13 @@
 	const char **args;
 };
 
-static void initcmdserveropts(struct cmdserveropts *opts) {
+static void initcmdserveropts(struct cmdserveropts *opts)
+{
 	memset(opts, 0, sizeof(struct cmdserveropts));
 }
 
-static void freecmdserveropts(struct cmdserveropts *opts) {
+static void freecmdserveropts(struct cmdserveropts *opts)
+{
 	free(opts->args);
 	opts->args = NULL;
 	opts->argsize = 0;
@@ -59,12 +61,8 @@
 		const char *name;
 		size_t narg;
 	} flags[] = {
-		{"--config", 1},
-		{"--cwd", 1},
-		{"--repo", 1},
-		{"--repository", 1},
-		{"--traceback", 0},
-		{"-R", 1},
+	    {"--config", 1},     {"--cwd", 1},       {"--repo", 1},
+	    {"--repository", 1}, {"--traceback", 0}, {"-R", 1},
 	};
 	size_t i;
 	for (i = 0; i < sizeof(flags) / sizeof(flags[0]); ++i) {
@@ -89,21 +87,21 @@
 /*
  * Parse argv[] and put sensitive flags to opts->args
  */
-static void setcmdserverargs(struct cmdserveropts *opts,
-			     int argc, const char *argv[])
+static void setcmdserverargs(struct cmdserveropts *opts, int argc,
+                             const char *argv[])
 {
 	size_t i, step;
 	opts->argsize = 0;
 	for (i = 0, step = 1; i < (size_t)argc; i += step, step = 1) {
 		if (!argv[i])
-			continue;  /* pass clang-analyse */
+			continue; /* pass clang-analyse */
 		if (strcmp(argv[i], "--") == 0)
 			break;
 		size_t n = testsensitiveflag(argv[i]);
 		if (n == 0 || i + n > (size_t)argc)
 			continue;
-		opts->args = reallocx(opts->args,
-				      (n + opts->argsize) * sizeof(char *));
+		opts->args =
+		    reallocx(opts->args, (n + opts->argsize) * sizeof(char *));
 		memcpy(opts->args + opts->argsize, argv + i,
 		       sizeof(char *) * n);
 		opts->argsize += n;
@@ -180,8 +178,8 @@
 	r = snprintf(opts->sockname, sizeof(opts->sockname), sockfmt, basename);
 	if (r < 0 || (size_t)r >= sizeof(opts->sockname))
 		abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r);
-	r = snprintf(opts->initsockname, sizeof(opts->initsockname),
-			"%s.%u", opts->sockname, (unsigned)getpid());
+	r = snprintf(opts->initsockname, sizeof(opts->initsockname), "%s.%u",
+	             opts->sockname, (unsigned)getpid());
 	if (r < 0 || (size_t)r >= sizeof(opts->initsockname))
 		abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r);
 }
@@ -208,11 +206,14 @@
 	const char *hgcmd = gethgcmd();
 
 	const char *baseargv[] = {
-		hgcmd,
-		"serve",
-		"--cmdserver", "chgunix",
-		"--address", opts->initsockname,
-		"--daemon-postexec", "chdir:/",
+	    hgcmd,
+	    "serve",
+	    "--cmdserver",
+	    "chgunix",
+	    "--address",
+	    opts->initsockname,
+	    "--daemon-postexec",
+	    "chdir:/",
 	};
 	size_t baseargvsize = sizeof(baseargv) / sizeof(baseargv[0]);
 	size_t argsize = baseargvsize + opts->argsize + 1;
@@ -237,7 +238,7 @@
 
 	debugmsg("try connect to %s repeatedly", opts->initsockname);
 
-	unsigned int timeoutsec = 60;  /* default: 60 seconds */
+	unsigned int timeoutsec = 60; /* default: 60 seconds */
 	const char *timeoutenv = getenv("CHGTIMEOUT");
 	if (timeoutenv)
 		sscanf(timeoutenv, "%u", &timeoutsec);
@@ -246,7 +247,7 @@
 		hgclient_t *hgc = hgc_open(opts->initsockname);
 		if (hgc) {
 			debugmsg("rename %s to %s", opts->initsockname,
-					opts->sockname);
+			         opts->sockname);
 			int r = rename(opts->initsockname, opts->sockname);
 			if (r != 0)
 				abortmsgerrno("cannot rename");
@@ -270,7 +271,7 @@
 	if (WIFEXITED(pst)) {
 		if (WEXITSTATUS(pst) == 0)
 			abortmsg("could not connect to cmdserver "
-				 "(exited with status 0)");
+			         "(exited with status 0)");
 		debugmsg("cmdserver exited with status %d", WEXITSTATUS(pst));
 		exit(WEXITSTATUS(pst));
 	} else if (WIFSIGNALED(pst)) {
@@ -284,8 +285,8 @@
 /* Connect to a cmdserver. Will start a new server on demand. */
 static hgclient_t *connectcmdserver(struct cmdserveropts *opts)
 {
-	const char *sockname = opts->redirectsockname[0] ?
-		opts->redirectsockname : opts->sockname;
+	const char *sockname =
+	    opts->redirectsockname[0] ? opts->redirectsockname : opts->sockname;
 	debugmsg("try connect to %s", sockname);
 	hgclient_t *hgc = hgc_open(sockname);
 	if (hgc)
@@ -339,8 +340,8 @@
 			unlink(*pinst + 7);
 		} else if (strncmp(*pinst, "redirect ", 9) == 0) {
 			int r = snprintf(opts->redirectsockname,
-					 sizeof(opts->redirectsockname),
-					 "%s", *pinst + 9);
+			                 sizeof(opts->redirectsockname), "%s",
+			                 *pinst + 9);
 			if (r < 0 || r >= (int)sizeof(opts->redirectsockname))
 				abortmsg("redirect path is too long (%d)", r);
 			needreconnect = 1;
@@ -365,10 +366,9 @@
  */
 static int isunsupported(int argc, const char *argv[])
 {
-	enum {
-		SERVE = 1,
-		DAEMON = 2,
-		SERVEDAEMON = SERVE | DAEMON,
+	enum { SERVE = 1,
+	       DAEMON = 2,
+	       SERVEDAEMON = SERVE | DAEMON,
 	};
 	unsigned int state = 0;
 	int i;
@@ -378,7 +378,7 @@
 		if (i == 0 && strcmp("serve", argv[i]) == 0)
 			state |= SERVE;
 		else if (strcmp("-d", argv[i]) == 0 ||
-			 strcmp("--daemon", argv[i]) == 0)
+		         strcmp("--daemon", argv[i]) == 0)
 			state |= DAEMON;
 	}
 	return (state & SERVEDAEMON) == SERVEDAEMON;
@@ -401,9 +401,9 @@
 
 	if (getenv("CHGINTERNALMARK"))
 		abortmsg("chg started by chg detected.\n"
-			 "Please make sure ${HG:-hg} is not a symlink or "
-			 "wrapper to chg. Alternatively, set $CHGHG to the "
-			 "path of real hg.");
+		         "Please make sure ${HG:-hg} is not a symlink or "
+		         "wrapper to chg. Alternatively, set $CHGHG to the "
+		         "path of real hg.");
 
 	if (isunsupported(argc - 1, argv + 1))
 		execoriginalhg(argv);
@@ -435,11 +435,11 @@
 		hgc_close(hgc);
 		if (++retry > 10)
 			abortmsg("too many redirections.\n"
-				 "Please make sure %s is not a wrapper which "
-				 "changes sensitive environment variables "
-				 "before executing hg. If you have to use a "
-				 "wrapper, wrap chg instead of hg.",
-				 gethgcmd());
+			         "Please make sure %s is not a wrapper which "
+			         "changes sensitive environment variables "
+			         "before executing hg. If you have to use a "
+			         "wrapper, wrap chg instead of hg.",
+			         gethgcmd());
 	}
 
 	setupsignalhandler(hgc_peerpid(hgc), hgc_peerpgid(hgc));
--- a/contrib/chg/hgclient.c	Wed Feb 07 06:28:43 2018 -0500
+++ b/contrib/chg/hgclient.c	Tue Feb 06 05:24:28 2018 -0500
@@ -7,7 +7,7 @@
  * GNU General Public License version 2 or any later version.
  */
 
-#include <arpa/inet.h>  /* for ntohl(), htonl() */
+#include <arpa/inet.h> /* for ntohl(), htonl() */
 #include <assert.h>
 #include <ctype.h>
 #include <errno.h>
@@ -26,16 +26,15 @@
 #include "procutil.h"
 #include "util.h"
 
-enum {
-	CAP_GETENCODING = 0x0001,
-	CAP_RUNCOMMAND = 0x0002,
-	/* cHg extension: */
-	CAP_ATTACHIO = 0x0100,
-	CAP_CHDIR = 0x0200,
-	CAP_SETENV = 0x0800,
-	CAP_SETUMASK = 0x1000,
-	CAP_VALIDATE = 0x2000,
-	CAP_SETPROCNAME = 0x4000,
+enum { CAP_GETENCODING = 0x0001,
+       CAP_RUNCOMMAND = 0x0002,
+       /* cHg extension: */
+       CAP_ATTACHIO = 0x0100,
+       CAP_CHDIR = 0x0200,
+       CAP_SETENV = 0x0800,
+       CAP_SETUMASK = 0x1000,
+       CAP_VALIDATE = 0x2000,
+       CAP_SETPROCNAME = 0x4000,
 };
 
 typedef struct {
@@ -44,15 +43,15 @@
 } cappair_t;
 
 static const cappair_t captable[] = {
-	{"getencoding", CAP_GETENCODING},
-	{"runcommand", CAP_RUNCOMMAND},
-	{"attachio", CAP_ATTACHIO},
-	{"chdir", CAP_CHDIR},
-	{"setenv", CAP_SETENV},
-	{"setumask", CAP_SETUMASK},
-	{"validate", CAP_VALIDATE},
-	{"setprocname", CAP_SETPROCNAME},
-	{NULL, 0},  /* terminator */
+    {"getencoding", CAP_GETENCODING},
+    {"runcommand", CAP_RUNCOMMAND},
+    {"attachio", CAP_ATTACHIO},
+    {"chdir", CAP_CHDIR},
+    {"setenv", CAP_SETENV},
+    {"setumask", CAP_SETUMASK},
+    {"validate", CAP_VALIDATE},
+    {"setprocname", CAP_SETPROCNAME},
+    {NULL, 0}, /* terminator */
 };
 
 typedef struct {
@@ -88,8 +87,8 @@
 	if (newsize <= ctx->maxdatasize)
 		return;
 
-	newsize = defaultdatasize
-		* ((newsize + defaultdatasize - 1) / defaultdatasize);
+	newsize = defaultdatasize *
+	          ((newsize + defaultdatasize - 1) / defaultdatasize);
 	ctx->data = reallocx(ctx->data, newsize);
 	ctx->maxdatasize = newsize;
 	debugmsg("enlarge context buffer to %zu", ctx->maxdatasize);
@@ -126,12 +125,12 @@
 	enlargecontext(&hgc->ctx, hgc->ctx.datasize);
 
 	if (isupper(hgc->ctx.ch) && hgc->ctx.ch != 'S')
-		return;  /* assumes input request */
+		return; /* assumes input request */
 
 	size_t cursize = 0;
 	while (cursize < hgc->ctx.datasize) {
 		rsize = recv(hgc->sockfd, hgc->ctx.data + cursize,
-			     hgc->ctx.datasize - cursize, 0);
+		             hgc->ctx.datasize - cursize, 0);
 		if (rsize < 1)
 			abortmsg("failed to read data block");
 		cursize += rsize;
@@ -176,19 +175,19 @@
 /* Build '\0'-separated list of args. argsize < 0 denotes that args are
  * terminated by NULL. */
 static void packcmdargs(context_t *ctx, const char *const args[],
-			ssize_t argsize)
+                        ssize_t argsize)
 {
 	ctx->datasize = 0;
 	const char *const *const end = (argsize >= 0) ? args + argsize : NULL;
 	for (const char *const *it = args; it != end && *it; ++it) {
-		const size_t n = strlen(*it) + 1;  /* include '\0' */
+		const size_t n = strlen(*it) + 1; /* include '\0' */
 		enlargecontext(ctx, ctx->datasize + n);
 		memcpy(ctx->data + ctx->datasize, *it, n);
 		ctx->datasize += n;
 	}
 
 	if (ctx->datasize > 0)
-		--ctx->datasize;  /* strip last '\0' */
+		--ctx->datasize; /* strip last '\0' */
 }
 
 /* Extract '\0'-separated list of args to new buffer, terminated by NULL */
@@ -199,7 +198,7 @@
 	const char *s = ctx->data;
 	const char *e = ctx->data + ctx->datasize;
 	for (;;) {
-		if (nargs + 1 >= maxnargs) {  /* including last NULL */
+		if (nargs + 1 >= maxnargs) { /* including last NULL */
 			maxnargs += 256;
 			args = reallocx(args, maxnargs * sizeof(args[0]));
 		}
@@ -237,7 +236,7 @@
 {
 	context_t *ctx = &hgc->ctx;
 	enlargecontext(ctx, ctx->datasize + 1);
-	ctx->data[ctx->datasize] = '\0';  /* terminate last string */
+	ctx->data[ctx->datasize] = '\0'; /* terminate last string */
 
 	const char **args = unpackcmdargsnul(ctx);
 	if (!args[0] || !args[1] || !args[2])
@@ -269,8 +268,8 @@
 	for (;;) {
 		readchannel(hgc);
 		context_t *ctx = &hgc->ctx;
-		debugmsg("response read from channel %c, size %zu",
-			 ctx->ch, ctx->datasize);
+		debugmsg("response read from channel %c, size %zu", ctx->ch,
+		         ctx->datasize);
 		switch (ctx->ch) {
 		case 'o':
 			fwrite(ctx->data, sizeof(ctx->data[0]), ctx->datasize,
@@ -299,7 +298,7 @@
 		default:
 			if (isupper(ctx->ch))
 				abortmsg("cannot handle response (ch = %c)",
-					 ctx->ch);
+				         ctx->ch);
 		}
 	}
 }
@@ -366,8 +365,8 @@
 
 static void updateprocname(hgclient_t *hgc)
 {
-	int r = snprintf(hgc->ctx.data, hgc->ctx.maxdatasize,
-			"chg[worker/%d]", (int)getpid());
+	int r = snprintf(hgc->ctx.data, hgc->ctx.maxdatasize, "chg[worker/%d]",
+	                 (int)getpid());
 	if (r < 0 || (size_t)r >= hgc->ctx.maxdatasize)
 		abortmsg("insufficient buffer to write procname (r = %d)", r);
 	hgc->ctx.datasize = (size_t)r;
@@ -387,7 +386,7 @@
 	static const int fds[3] = {STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO};
 	struct msghdr msgh;
 	memset(&msgh, 0, sizeof(msgh));
-	struct iovec iov = {ctx->data, ctx->datasize};  /* dummy payload */
+	struct iovec iov = {ctx->data, ctx->datasize}; /* dummy payload */
 	msgh.msg_iov = &iov;
 	msgh.msg_iovlen = 1;
 	char fdbuf[CMSG_SPACE(sizeof(fds))];
@@ -552,7 +551,7 @@
  *           the last string is guaranteed to be NULL.
  */
 const char **hgc_validate(hgclient_t *hgc, const char *const args[],
-			  size_t argsize)
+                          size_t argsize)
 {
 	assert(hgc);
 	if (!(hgc->capflags & CAP_VALIDATE))
--- a/contrib/chg/hgclient.h	Wed Feb 07 06:28:43 2018 -0500
+++ b/contrib/chg/hgclient.h	Tue Feb 06 05:24:28 2018 -0500
@@ -22,9 +22,9 @@
 pid_t hgc_peerpid(const hgclient_t *hgc);
 
 const char **hgc_validate(hgclient_t *hgc, const char *const args[],
-			  size_t argsize);
+                          size_t argsize);
 int hgc_runcommand(hgclient_t *hgc, const char *const args[], size_t argsize);
 void hgc_attachio(hgclient_t *hgc);
 void hgc_setenv(hgclient_t *hgc, const char *const envp[]);
 
-#endif  /* HGCLIENT_H_ */
+#endif /* HGCLIENT_H_ */
--- a/contrib/chg/procutil.c	Wed Feb 07 06:28:43 2018 -0500
+++ b/contrib/chg/procutil.c	Tue Feb 06 05:24:28 2018 -0500
@@ -54,7 +54,7 @@
 		goto error;
 
 	forwardsignal(sig);
-	if (raise(sig) < 0)  /* resend to self */
+	if (raise(sig) < 0) /* resend to self */
 		goto error;
 	if (sigaction(sig, &sa, &oldsa) < 0)
 		goto error;
@@ -205,8 +205,8 @@
 		close(pipefds[0]);
 		close(pipefds[1]);
 
-		int r = execle("/bin/sh", "/bin/sh", "-c", pagercmd, NULL,
-				envp);
+		int r =
+		    execle("/bin/sh", "/bin/sh", "-c", pagercmd, NULL, envp);
 		if (r < 0) {
 			abortmsgerrno("cannot start pager '%s'", pagercmd);
 		}
--- a/contrib/chg/util.c	Wed Feb 07 06:28:43 2018 -0500
+++ b/contrib/chg/util.c	Tue Feb 06 05:24:28 2018 -0500
@@ -62,7 +62,8 @@
 static int debugmsgenabled = 0;
 static double debugstart = 0;
 
-static double now() {
+static double now()
+{
 	struct timeval t;
 	gettimeofday(&t, NULL);
 	return t.tv_usec / 1e6 + t.tv_sec;
--- a/contrib/chg/util.h	Wed Feb 07 06:28:43 2018 -0500
+++ b/contrib/chg/util.h	Tue Feb 06 05:24:28 2018 -0500
@@ -32,4 +32,4 @@
 
 int runshellcmd(const char *cmd, const char *envp[], const char *cwd);
 
-#endif  /* UTIL_H_ */
+#endif /* UTIL_H_ */
--- a/contrib/clang-format-blacklist	Wed Feb 07 06:28:43 2018 -0500
+++ b/contrib/clang-format-blacklist	Tue Feb 06 05:24:28 2018 -0500
@@ -1,12 +1,5 @@
 # Files that just need to be migrated to the formatter.
 # Do not add new files here!
-contrib/chg/chg.c
-contrib/chg/hgclient.c
-contrib/chg/hgclient.h
-contrib/chg/procutil.c
-contrib/chg/procutil.h
-contrib/chg/util.c
-contrib/chg/util.h
 contrib/hgsh/hgsh.c
 mercurial/cext/base85.c
 mercurial/cext/bdiff.c