From 18e95f279ec62cc8d5e5ab709b162ccc55eebf0a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 8 Jan 2010 05:53:56 -0800 Subject: ident.c: remove unused variables d5cc2de (ident.c: Trim hint printed when gecos is empty., 2006-11-28) reworded the message used as printf() format and dropped "%s" from it; these two variables that hold the names of GIT_{AUTHOR,COMMITTER}_NAME environment variables haven't been used since then. Signed-off-by: Junio C Hamano diff --git a/ident.c b/ident.c index 26409b2..e6c1798 100644 --- a/ident.c +++ b/ident.c @@ -168,8 +168,6 @@ static int copy(char *buf, size_t size, int offset, const char *src) return offset; } -static const char au_env[] = "GIT_AUTHOR_NAME"; -static const char co_env[] = "GIT_COMMITTER_NAME"; static const char *env_hint = "\n" "*** Please tell me who you are.\n" @@ -204,7 +202,7 @@ const char *fmt_ident(const char *name, const char *email, if ((warn_on_no_name || error_on_no_name) && name == git_default_name && env_hint) { - fprintf(stderr, env_hint, au_env, co_env); + fprintf(stderr, env_hint); env_hint = NULL; /* warn only once */ } if (error_on_no_name) -- cgit v0.10.2-6-g49f6 From 91c38a21089c4b30d35f392386c752a017ac6db0 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 8 Jan 2010 07:39:11 -0800 Subject: ident.c: check explicit identity for name and email separately MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Acked-by: Santi BĂ©jar diff --git a/builtin-commit.c b/builtin-commit.c index 073fe90..f4974b5 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -624,7 +624,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, author_ident); free(author_ident); - if (!user_ident_explicitly_given) + if (user_ident_explicitly_given != IDENT_ALL_GIVEN) fprintf(fp, "%s" "# Committer: %s\n", diff --git a/cache.h b/cache.h index bf468e5..16c8e8d 100644 --- a/cache.h +++ b/cache.h @@ -925,6 +925,9 @@ extern const char *config_exclusive_filename; #define MAX_GITNAME (1000) extern char git_default_email[MAX_GITNAME]; extern char git_default_name[MAX_GITNAME]; +#define IDENT_NAME_GIVEN 01 +#define IDENT_MAIL_GIVEN 02 +#define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN) extern int user_ident_explicitly_given; extern const char *git_commit_encoding; diff --git a/config.c b/config.c index 37385ce..fa1a0c0 100644 --- a/config.c +++ b/config.c @@ -528,8 +528,7 @@ static int git_default_user_config(const char *var, const char *value) if (!value) return config_error_nonbool(var); strlcpy(git_default_name, value, sizeof(git_default_name)); - if (git_default_email[0]) - user_ident_explicitly_given = 1; + user_ident_explicitly_given |= IDENT_NAME_GIVEN; return 0; } @@ -537,8 +536,7 @@ static int git_default_user_config(const char *var, const char *value) if (!value) return config_error_nonbool(var); strlcpy(git_default_email, value, sizeof(git_default_email)); - if (git_default_name[0]) - user_ident_explicitly_given = 1; + user_ident_explicitly_given |= IDENT_MAIL_GIVEN; return 0; } diff --git a/ident.c b/ident.c index e6c1798..e67c5ad 100644 --- a/ident.c +++ b/ident.c @@ -249,9 +249,10 @@ const char *git_author_info(int flag) const char *git_committer_info(int flag) { - if (getenv("GIT_COMMITTER_NAME") && - getenv("GIT_COMMITTER_EMAIL")) - user_ident_explicitly_given = 1; + if (getenv("GIT_COMMITTER_NAME")) + user_ident_explicitly_given |= IDENT_NAME_GIVEN; + if (getenv("GIT_COMMITTER_EMAIL")) + user_ident_explicitly_given |= IDENT_MAIL_GIVEN; return fmt_ident(getenv("GIT_COMMITTER_NAME"), getenv("GIT_COMMITTER_EMAIL"), getenv("GIT_COMMITTER_DATE"), -- cgit v0.10.2-6-g49f6 From 99178c831e72ba80b9edd5455b03070758c55526 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 8 Jan 2010 08:01:10 -0800 Subject: ident.c: treat $EMAIL as giving user.email identity explicitly The environment variable EMAIL has been honored since 28a94f8 (Fall back to $EMAIL for missing GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL, 2007-04-28) as the end-user's wish to use the address as the identity. When we use it, we should say we are explicitly given email by the user. Signed-off-by: Junio C Hamano diff --git a/ident.c b/ident.c index e67c5ad..d4f6145 100644 --- a/ident.c +++ b/ident.c @@ -85,10 +85,11 @@ static void setup_ident(void) if (!git_default_email[0]) { const char *email = getenv("EMAIL"); - if (email && email[0]) + if (email && email[0]) { strlcpy(git_default_email, email, sizeof(git_default_email)); - else { + user_ident_explicitly_given |= IDENT_MAIL_GIVEN; + } else { if (!pw) pw = getpwuid(getuid()); if (!pw) -- cgit v0.10.2-6-g49f6 From 5aeb3a3a838b2cb03d250f3376cf9c41f4d4608e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 17 Jan 2010 13:54:28 -0800 Subject: user_ident_sufficiently_given(): refactor the logic to be usable from elsewhere Signed-off-by: Junio C Hamano diff --git a/builtin-commit.c b/builtin-commit.c index f4974b5..b76f327 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -624,7 +624,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, author_ident); free(author_ident); - if (user_ident_explicitly_given != IDENT_ALL_GIVEN) + if (!user_ident_sufficiently_given()) fprintf(fp, "%s" "# Committer: %s\n", diff --git a/cache.h b/cache.h index 16c8e8d..f7a287c 100644 --- a/cache.h +++ b/cache.h @@ -929,6 +929,7 @@ extern char git_default_name[MAX_GITNAME]; #define IDENT_MAIL_GIVEN 02 #define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN) extern int user_ident_explicitly_given; +extern int user_ident_sufficiently_given(void); extern const char *git_commit_encoding; extern const char *git_log_output_encoding; diff --git a/ident.c b/ident.c index d4f6145..96b56e6 100644 --- a/ident.c +++ b/ident.c @@ -259,3 +259,12 @@ const char *git_committer_info(int flag) getenv("GIT_COMMITTER_DATE"), flag); } + +int user_ident_sufficiently_given(void) +{ +#ifndef WINDOWS + return (user_ident_explicitly_given & IDENT_MAIL_GIVEN); +#else + return (user_ident_explicitly_given == IDENT_ALL_GIVEN); +#endif +} -- cgit v0.10.2-6-g49f6 From 8b770a2a24456089c0dd0230035a7d88aee7e26a Mon Sep 17 00:00:00 2001 From: Tarmigan Casebolt Date: Sun, 17 Jan 2010 00:19:24 -0800 Subject: ident.c: replace fprintf with fputs to suppress compiler warning Compiling today's pu gave ... CC ident.o CC levenshtein.o ident.c: In function 'fmt_ident': ident.c:206: warning: format not a string literal and no format arguments CC list-objects.o ... This warning seems to have appeared first in 18e95f279ec6 (ident.c: remove unused variables) which removed additional fprintf arguments. Suppress this warning by using fputs instead of fprintf. Signed-off-by: Tarmigan Casebolt Signed-off-by: Junio C Hamano diff --git a/ident.c b/ident.c index 96b56e6..9e24388 100644 --- a/ident.c +++ b/ident.c @@ -203,7 +203,7 @@ const char *fmt_ident(const char *name, const char *email, if ((warn_on_no_name || error_on_no_name) && name == git_default_name && env_hint) { - fprintf(stderr, env_hint); + fputs(env_hint, stderr); env_hint = NULL; /* warn only once */ } if (error_on_no_name) -- cgit v0.10.2-6-g49f6