builtin/commit.c: use xstrdup_or_null instead of envdup

The only reason for envdup to be its own function is that we
have to save the result in a temporary string. With
xstrdup_or_null, we can feed the result of getenv()
directly.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Jeff King 2015-01-12 20:58:33 -05:00 committed by Junio C Hamano
parent 4440690786
commit eaa541eb59
1 changed files with 3 additions and 9 deletions

View File

@ -566,20 +566,14 @@ static void set_ident_var(char **buf, char *val)
*buf = val; *buf = val;
} }


static char *envdup(const char *var)
{
const char *val = getenv(var);
return val ? xstrdup(val) : NULL;
}

static void determine_author_info(struct strbuf *author_ident) static void determine_author_info(struct strbuf *author_ident)
{ {
char *name, *email, *date; char *name, *email, *date;
struct ident_split author; struct ident_split author;


name = envdup("GIT_AUTHOR_NAME"); name = xstrdup_or_null(getenv("GIT_AUTHOR_NAME"));
email = envdup("GIT_AUTHOR_EMAIL"); email = xstrdup_or_null(getenv("GIT_AUTHOR_EMAIL"));
date = envdup("GIT_AUTHOR_DATE"); date = xstrdup_or_null(getenv("GIT_AUTHOR_DATE"));


if (author_message) { if (author_message) {
struct ident_split ident; struct ident_split ident;