ident.c: check explicit identity for name and email separately
bb1ae3f (commit: Show committer if automatic, 2008-05-04) added a logic to check both name and email were given explicitly by the end user, but it assumed that fmt_ident() is never called before git_default_user_config() is called, which was fragile. The former calls setup_ident() and fills the "default" name and email, so the check in the config parser would have mistakenly said both are given even if only user.name was provided. Make the logic more robust by keeping track of name and email separately. Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Santi Béjar <santi@agolina.net>
Junio C Hamano committed
Jan 8, 2010 at 07:39 UTC
91c38a21089c4b30d35f392386c752a017ac6db0
4 files changed
+10
-8
builtin-commit.c
+1
-1
@@ -624,7 +624,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
624
author_ident);
625
free(author_ident);
626
627
- if (!user_ident_explicitly_given)
627
+ if (user_ident_explicitly_given != IDENT_ALL_GIVEN)
628
fprintf(fp,
629
"%s"
630
"# Committer: %s\n",
cache.h
+3
@@ -925,6 +925,9 @@ extern const char *config_exclusive_filename;
925
#define MAX_GITNAME (1000)
926
extern char git_default_email[MAX_GITNAME];
927
extern char git_default_name[MAX_GITNAME];
928
+#define IDENT_NAME_GIVEN 01
929
+#define IDENT_MAIL_GIVEN 02
930
+#define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN)
931
extern int user_ident_explicitly_given;
932
933
extern const char *git_commit_encoding;
config.c
+2
-4
@@ -528,8 +528,7 @@ static int git_default_user_config(const char *var, const char *value)
528
if (!value)
529
return config_error_nonbool(var);
530
strlcpy(git_default_name, value, sizeof(git_default_name));
531
- if (git_default_email[0])
532
- user_ident_explicitly_given = 1;
531
+ user_ident_explicitly_given |= IDENT_NAME_GIVEN;
532
return 0;
533
}
534
@@ -537,8 +536,7 @@ static int git_default_user_config(const char *var, const char *value)
536
if (!value)
537
return config_error_nonbool(var);
538
strlcpy(git_default_email, value, sizeof(git_default_email));
540
- if (git_default_name[0])
541
- user_ident_explicitly_given = 1;
539
+ user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
540
return 0;
541
}
542
ident.c
+4
-3
@@ -249,9 +249,10 @@ const char *git_author_info(int flag)
249
250
const char *git_committer_info(int flag)
251
{
252
- if (getenv("GIT_COMMITTER_NAME") &&
253
- getenv("GIT_COMMITTER_EMAIL"))
254
- user_ident_explicitly_given = 1;
252
+ if (getenv("GIT_COMMITTER_NAME"))
253
+ user_ident_explicitly_given |= IDENT_NAME_GIVEN;
254
+ if (getenv("GIT_COMMITTER_EMAIL"))
255
+ user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
256
return fmt_ident(getenv("GIT_COMMITTER_NAME"),
257
getenv("GIT_COMMITTER_EMAIL"),
258
getenv("GIT_COMMITTER_DATE"),