Skip to content

Commit d6991ce

Browse files
peffgitster
authored andcommitted
ident: keep separate "explicit" flags for author and committer
We keep track of whether the user ident was given to us explicitly, or if we guessed at it from system parameters like username and hostname. However, we kept only a single variable. This covers the common cases (because the author and committer will usually come from the same explicit source), but can miss two cases: 1. GIT_COMMITTER_* is set explicitly, but we fallback for GIT_AUTHOR. We claim the ident is explicit, even though the author is not. 2. GIT_AUTHOR_* is set and we ask for author ident, but not committer ident. We will claim the ident is implicit, even though it is explicit. This patch uses two variables instead of one, updates both when we set the "fallback" values, and updates them individually when we read from the environment. Rather than keep user_ident_sufficiently_given as a compatibility wrapper, we update the only two callers to check the committer_ident, which matches their intent and what was happening already. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4528023 commit d6991ce

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

builtin/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
755755
ident_shown++ ? "" : "\n",
756756
author_ident->buf);
757757

758-
if (!user_ident_sufficiently_given())
758+
if (!committer_ident_sufficiently_given())
759759
status_printf_ln(s, GIT_COLOR_NORMAL,
760760
_("%s"
761761
"Committer: %s"),
@@ -1265,7 +1265,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
12651265
strbuf_addstr(&format, "\n Author: ");
12661266
strbuf_addbuf_percentquote(&format, &author_ident);
12671267
}
1268-
if (!user_ident_sufficiently_given()) {
1268+
if (!committer_ident_sufficiently_given()) {
12691269
strbuf_addstr(&format, "\n Committer: ");
12701270
strbuf_addbuf_percentquote(&format, &committer_ident);
12711271
if (advice_implicit_identity) {

cache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,8 @@ struct config_include_data {
11491149
#define CONFIG_INCLUDE_INIT { 0 }
11501150
extern int git_config_include(const char *name, const char *value, void *data);
11511151

1152-
extern int user_ident_sufficiently_given(void);
1152+
extern int committer_ident_sufficiently_given(void);
1153+
extern int author_ident_sufficiently_given(void);
11531154

11541155
extern const char *git_commit_encoding;
11551156
extern const char *git_log_output_encoding;

ident.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ static char git_default_date[50];
1414
#define IDENT_NAME_GIVEN 01
1515
#define IDENT_MAIL_GIVEN 02
1616
#define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN)
17-
static int user_ident_explicitly_given;
17+
static int committer_ident_explicitly_given;
18+
static int author_ident_explicitly_given;
1819

1920
#ifdef NO_GECOS_IN_PWENT
2021
#define get_gecos(ignored) "&"
@@ -113,7 +114,8 @@ const char *ident_default_email(void)
113114

114115
if (email && email[0]) {
115116
strbuf_addstr(&git_default_email, email);
116-
user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
117+
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
118+
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
117119
} else
118120
copy_email(xgetpwuid_self(), &git_default_email);
119121
strbuf_trim(&git_default_email);
@@ -331,6 +333,10 @@ const char *fmt_name(const char *name, const char *email)
331333

332334
const char *git_author_info(int flag)
333335
{
336+
if (getenv("GIT_AUTHOR_NAME"))
337+
author_ident_explicitly_given |= IDENT_NAME_GIVEN;
338+
if (getenv("GIT_AUTHOR_EMAIL"))
339+
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
334340
return fmt_ident(getenv("GIT_AUTHOR_NAME"),
335341
getenv("GIT_AUTHOR_EMAIL"),
336342
getenv("GIT_AUTHOR_DATE"),
@@ -340,16 +346,16 @@ const char *git_author_info(int flag)
340346
const char *git_committer_info(int flag)
341347
{
342348
if (getenv("GIT_COMMITTER_NAME"))
343-
user_ident_explicitly_given |= IDENT_NAME_GIVEN;
349+
committer_ident_explicitly_given |= IDENT_NAME_GIVEN;
344350
if (getenv("GIT_COMMITTER_EMAIL"))
345-
user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
351+
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
346352
return fmt_ident(getenv("GIT_COMMITTER_NAME"),
347353
getenv("GIT_COMMITTER_EMAIL"),
348354
getenv("GIT_COMMITTER_DATE"),
349355
flag);
350356
}
351357

352-
int user_ident_sufficiently_given(void)
358+
static int ident_is_sufficient(int user_ident_explicitly_given)
353359
{
354360
#ifndef WINDOWS
355361
return (user_ident_explicitly_given & IDENT_MAIL_GIVEN);
@@ -358,14 +364,25 @@ int user_ident_sufficiently_given(void)
358364
#endif
359365
}
360366

367+
int committer_ident_sufficiently_given(void)
368+
{
369+
return ident_is_sufficient(committer_ident_explicitly_given);
370+
}
371+
372+
int author_ident_sufficiently_given(void)
373+
{
374+
return ident_is_sufficient(author_ident_explicitly_given);
375+
}
376+
361377
int git_ident_config(const char *var, const char *value, void *data)
362378
{
363379
if (!strcmp(var, "user.name")) {
364380
if (!value)
365381
return config_error_nonbool(var);
366382
strbuf_reset(&git_default_name);
367383
strbuf_addstr(&git_default_name, value);
368-
user_ident_explicitly_given |= IDENT_NAME_GIVEN;
384+
committer_ident_explicitly_given |= IDENT_NAME_GIVEN;
385+
author_ident_explicitly_given |= IDENT_NAME_GIVEN;
369386
return 0;
370387
}
371388

@@ -374,7 +391,8 @@ int git_ident_config(const char *var, const char *value, void *data)
374391
return config_error_nonbool(var);
375392
strbuf_reset(&git_default_email);
376393
strbuf_addstr(&git_default_email, value);
377-
user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
394+
committer_ident_explicitly_given |= IDENT_MAIL_GIVEN;
395+
author_ident_explicitly_given |= IDENT_MAIL_GIVEN;
378396
return 0;
379397
}
380398

0 commit comments

Comments
 (0)