Skip to content

Commit 6e54a32

Browse files
avargitster
authored andcommitted
daemon.c: refactor hostinfo_init() to HOSTINFO_INIT macro
Remove the hostinfo_init() function added in 01cec54 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a30321b commit 6e54a32

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

daemon.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ struct hostinfo {
6363
unsigned int hostname_lookup_done:1;
6464
unsigned int saw_extended_args:1;
6565
};
66+
#define HOSTINFO_INIT { \
67+
.hostname = STRBUF_INIT, \
68+
.canon_hostname = STRBUF_INIT, \
69+
.ip_address = STRBUF_INIT, \
70+
.tcp_port = STRBUF_INIT, \
71+
}
6672

6773
static void lookup_hostname(struct hostinfo *hi);
6874

@@ -727,15 +733,6 @@ static void lookup_hostname(struct hostinfo *hi)
727733
}
728734
}
729735

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-
739736
static void hostinfo_clear(struct hostinfo *hi)
740737
{
741738
strbuf_release(&hi->hostname);
@@ -760,11 +757,9 @@ static int execute(void)
760757
char *line = packet_buffer;
761758
int pktlen, len, i;
762759
char *addr = getenv("REMOTE_ADDR"), *port = getenv("REMOTE_PORT");
763-
struct hostinfo hi;
760+
struct hostinfo hi = HOSTINFO_INIT;
764761
struct strvec env = STRVEC_INIT;
765762

766-
hostinfo_init(&hi);
767-
768763
if (addr)
769764
loginfo("Connection from %s:%s", addr, port);
770765

0 commit comments

Comments
 (0)