]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ident: trim whitespace from default name/email
authorJeff King <peff@peff.net>
Mon, 21 May 2012 23:10:29 +0000 (19:10 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 22 May 2012 16:08:49 +0000 (09:08 -0700)
Usually these values get fed to fmt_ident, which will trim
any cruft anyway, but there are a few code paths which use
them directly. Let's clean them up for the benefit of those
callers. Furthermore, fmt_ident will look at the pre-trimmed
value and decide whether to invoke ERROR_ON_NO_NAME; this
check can be fooled by a name consisting only of spaces.

Note that we only bother to clean up when we are pulling the
information from gecos or from system files. Any other value
comes from a config file, where we will have cleaned up
accidental whitespace already.

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 cefb8294c3d559575e9805a9f3e3c4bef891ed7a..e279039ac526503587bb6723b12181f70b9dbb6a 100644 (file)
--- a/ident.c
+++ b/ident.c
@@ -95,8 +95,10 @@ static void copy_email(const struct passwd *pw, struct strbuf *email)
 
 const char *ident_default_name(void)
 {
-       if (!git_default_name.len)
+       if (!git_default_name.len) {
                copy_gecos(xgetpwuid_self(), &git_default_name);
+               strbuf_trim(&git_default_name);
+       }
        return git_default_name.buf;
 }
 
@@ -110,6 +112,7 @@ const char *ident_default_email(void)
                        user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
                } else
                        copy_email(xgetpwuid_self(), &git_default_email);
+               strbuf_trim(&git_default_email);
        }
        return git_default_email.buf;
 }