daemon.c: refactor hostinfo_init() to HOSTINFO_INIT macro

Remove the hostinfo_init() function added in 01cec54e135 (daemon: deglobalize hostname information, 2015-03-07) and instead initialize the "struct hostinfo" with a macro. This is the more idiomatic pattern in the codebase, and doesn't leave us wondering when we see the *_init() function if this struct needs more complex initialization than a macro can provide. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Sep 27, 2021 at 14:58 UTC 6e54a32468e209aa724b37496fcc63f4ebe84f60
1 file changed +7 -12
daemon.c
+7 -12
@@ -63,6 +63,12 @@ struct hostinfo {
63 unsigned int hostname_lookup_done:1;
64 unsigned int saw_extended_args:1;
65 };
66 +#define HOSTINFO_INIT { \
67 + .hostname = STRBUF_INIT, \
68 + .canon_hostname = STRBUF_INIT, \
69 + .ip_address = STRBUF_INIT, \
70 + .tcp_port = STRBUF_INIT, \
71 +}
72
73 static void lookup_hostname(struct hostinfo *hi);
74
@@ -727,15 +733,6 @@ static void lookup_hostname(struct hostinfo *hi)
733 }
734 }
735
730 -static void hostinfo_init(struct hostinfo *hi)
731 -{
732 - memset(hi, 0, sizeof(*hi));
733 - strbuf_init(&hi->hostname, 0);
734 - strbuf_init(&hi->canon_hostname, 0);
735 - strbuf_init(&hi->ip_address, 0);
736 - strbuf_init(&hi->tcp_port, 0);
737 -}
738 -
736 static void hostinfo_clear(struct hostinfo *hi)
737 {
738 strbuf_release(&hi->hostname);
@@ -760,11 +757,9 @@ static int execute(void)
757 char *line = packet_buffer;
758 int pktlen, len, i;
759 char *addr = getenv("REMOTE_ADDR"), *port = getenv("REMOTE_PORT");
763 - struct hostinfo hi;
760 + struct hostinfo hi = HOSTINFO_INIT;
761 struct strvec env = STRVEC_INIT;
762
766 - hostinfo_init(&hi);
767 -
763 if (addr)
764 loginfo("Connection from %s:%s", addr, port);
765