Subject: [PATCH v1 20/25] structured-logging: add structured logging to remote-curl

From: [email-masked]
Date: Fri, 13 Jul 2018 16:56:16 +0000

From: Jeff Hostetler <[email-masked]>

remote-curl is not a builtin command and therefore, does not inherit
the common cmd_main() startup in git.c

Wrap cmd_main() with slog_cmd_main() in remote-curl to initialize
logging.

Add slog timers around push, fetch, and list verbs.

Signed-off-by: Jeff Hostetler <[email-masked]>
---
 remote-curl.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/remote-curl.c b/remote-curl.c
index 99b0bed..ed910f8 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1322,8 +1322,9 @@ static int stateless_connect(const char *service_name)
 	return 0;
 }
 
-int cmd_main(int argc, const char **argv)
+static int real_cmd_main(int argc, const char **argv)
 {
+	int slog_tid;
 	struct strbuf buf = STRBUF_INIT;
 	int nongit;
 
@@ -1333,6 +1334,8 @@ int cmd_main(int argc, const char **argv)
 		return 1;
 	}
 
+	slog_set_command_name("remote-curl");
+
 	options.verbosity = 1;
 	options.progress = !!isatty(2);
 	options.thin = 1;
@@ -1362,14 +1365,20 @@ int cmd_main(int argc, const char **argv)
 		if (starts_with(buf.buf, "fetch ")) {
 			if (nongit)
 				die("remote-curl: fetch attempted without a local repo");
+			slog_tid = slog_start_timer("curl", "fetch");
 			parse_fetch(&buf);
+			slog_stop_timer(slog_tid);
 
 		} else if (!strcmp(buf.buf, "list") || starts_with(buf.buf, "list ")) {
 			int for_push = !!strstr(buf.buf + 4, "for-push");
+			slog_tid = slog_start_timer("curl", "list");
 			output_refs(get_refs(for_push));
+			slog_stop_timer(slog_tid);
 
 		} else if (starts_with(buf.buf, "push ")) {
+			slog_tid = slog_start_timer("curl", "push");
 			parse_push(&buf);
+			slog_stop_timer(slog_tid);
 
 		} else if (skip_prefix(buf.buf, "option ", &arg)) {
 			char *value = strchr(arg, ' ');
@@ -1411,3 +1420,8 @@ int cmd_main(int argc, const char **argv)
 
 	return 0;
 }
+
+int cmd_main(int argc, const char **argv)
+{
+	return slog_wrap_main(real_cmd_main, argc, argv);
+}
-- 
2.9.3