ident: trim trailing newline from /etc/mailname
authorJeff King <peff@peff.net>
Mon, 21 May 2012 23:10:02 +0000 (19:10 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 22 May 2012 16:07:53 +0000 (09:07 -0700)
We use fgets to read the /etc/mailname file, which means we
will typically end up with an extra newline in our
git_default_email. Most of the time this doesn't matter, as
fmt_ident will skip it as cruft, but there is one code path
that accesses it directly (in http-push.c:lock_remote).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ident.c

diff --git a/ident.c b/ident.c
index af92b2cd86ebec47ceb57b3bad758ab05e3d5fe0..acb3a0843f40a10a730a80e7fcbf896660184a42 100644 (file)
--- a/ident.c
+++ b/ident.c
@@ -74,6 +74,10 @@ static int add_mailname_host(char *buf, size_t len)
        }
        /* success! */
        fclose(mailname);
+
+       len = strlen(buf);
+       if (len && buf[len-1] == '\n')
+               buf[len-1] = '\0';
        return 0;
 }