Merge branch 'jc/ident'

* jc/ident:
  ident.c: replace fprintf with fputs to suppress compiler warning
  user_ident_sufficiently_given(): refactor the logic to be usable from elsewhere
  ident.c: treat $EMAIL as giving user.email identity explicitly
  ident.c: check explicit identity for name and email separately
  ident.c: remove unused variables
maint
Junio C Hamano 2010-01-20 14:39:52 -08:00
commit 15a873d6e8
4 changed files with 24 additions and 13 deletions

View File

@ -633,7 +633,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
author_ident); author_ident);
free(author_ident); free(author_ident);


if (!user_ident_explicitly_given) if (!user_ident_sufficiently_given())
fprintf(fp, fprintf(fp,
"%s" "%s"
"# Committer: %s\n", "# Committer: %s\n",

View File

@ -931,7 +931,11 @@ extern const char *config_exclusive_filename;
#define MAX_GITNAME (1000) #define MAX_GITNAME (1000)
extern char git_default_email[MAX_GITNAME]; extern char git_default_email[MAX_GITNAME];
extern char git_default_name[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 int user_ident_explicitly_given;
extern int user_ident_sufficiently_given(void);


extern const char *git_commit_encoding; extern const char *git_commit_encoding;
extern const char *git_log_output_encoding; extern const char *git_log_output_encoding;

View File

@ -533,8 +533,7 @@ static int git_default_user_config(const char *var, const char *value)
if (!value) if (!value)
return config_error_nonbool(var); return config_error_nonbool(var);
strlcpy(git_default_name, value, sizeof(git_default_name)); strlcpy(git_default_name, value, sizeof(git_default_name));
if (git_default_email[0]) user_ident_explicitly_given |= IDENT_NAME_GIVEN;
user_ident_explicitly_given = 1;
return 0; return 0;
} }


@ -542,8 +541,7 @@ static int git_default_user_config(const char *var, const char *value)
if (!value) if (!value)
return config_error_nonbool(var); return config_error_nonbool(var);
strlcpy(git_default_email, value, sizeof(git_default_email)); strlcpy(git_default_email, value, sizeof(git_default_email));
if (git_default_name[0]) user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
user_ident_explicitly_given = 1;
return 0; return 0;
} }



25
ident.c
View File

@ -85,10 +85,11 @@ static void setup_ident(void)
if (!git_default_email[0]) { if (!git_default_email[0]) {
const char *email = getenv("EMAIL"); const char *email = getenv("EMAIL");


if (email && email[0]) if (email && email[0]) {
strlcpy(git_default_email, email, strlcpy(git_default_email, email,
sizeof(git_default_email)); sizeof(git_default_email));
else { user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
} else {
if (!pw) if (!pw)
pw = getpwuid(getuid()); pw = getpwuid(getuid());
if (!pw) if (!pw)
@ -168,8 +169,6 @@ static int copy(char *buf, size_t size, int offset, const char *src)
return offset; return offset;
} }


static const char au_env[] = "GIT_AUTHOR_NAME";
static const char co_env[] = "GIT_COMMITTER_NAME";
static const char *env_hint = static const char *env_hint =
"\n" "\n"
"*** Please tell me who you are.\n" "*** Please tell me who you are.\n"
@ -204,7 +203,7 @@ const char *fmt_ident(const char *name, const char *email,


if ((warn_on_no_name || error_on_no_name) && if ((warn_on_no_name || error_on_no_name) &&
name == git_default_name && env_hint) { name == git_default_name && env_hint) {
fprintf(stderr, env_hint, au_env, co_env); fputs(env_hint, stderr);
env_hint = NULL; /* warn only once */ env_hint = NULL; /* warn only once */
} }
if (error_on_no_name) if (error_on_no_name)
@ -251,11 +250,21 @@ const char *git_author_info(int flag)


const char *git_committer_info(int flag) const char *git_committer_info(int flag)
{ {
if (getenv("GIT_COMMITTER_NAME") && if (getenv("GIT_COMMITTER_NAME"))
getenv("GIT_COMMITTER_EMAIL")) user_ident_explicitly_given |= IDENT_NAME_GIVEN;
user_ident_explicitly_given = 1; if (getenv("GIT_COMMITTER_EMAIL"))
user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
return fmt_ident(getenv("GIT_COMMITTER_NAME"), return fmt_ident(getenv("GIT_COMMITTER_NAME"),
getenv("GIT_COMMITTER_EMAIL"), getenv("GIT_COMMITTER_EMAIL"),
getenv("GIT_COMMITTER_DATE"), getenv("GIT_COMMITTER_DATE"),
flag); 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
}