ident: trim whitespace from default name/email
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>
Jeff King committed
May 21, 2012 at 19:10 UTC
be641abdb544f00adb7ae6fdab41f9bd5453e206
1 file changed
+4
-1
ident.c
+4
-1
@@ -95,8 +95,10 @@ static void copy_email(const struct passwd *pw, struct strbuf *email)
95
96
const char *ident_default_name(void)
97
{
98
- if (!git_default_name.len)
98
+ if (!git_default_name.len) {
99
copy_gecos(xgetpwuid_self(), &git_default_name);
100
+ strbuf_trim(&git_default_name);
101
+ }
102
return git_default_name.buf;
103
}
104
@@ -110,6 +112,7 @@ const char *ident_default_email(void)
112
user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
113
} else
114
copy_email(xgetpwuid_self(), &git_default_email);
115
+ strbuf_trim(&git_default_email);
116
}
117
return git_default_email.buf;
118
}