path: root/ident.c
diff options
authorJunio C Hamano <>2007-12-09 01:32:08 (GMT)
committerJunio C Hamano <>2007-12-09 08:55:55 (GMT)
commit774751a8bc594a5b56039bbdc43c45e3882dd804 (patch)
tree60e5459a634d34763ff783a58e7732869f841e74 /ident.c
parent264474f29a3f41124f98e955b41ebe4e36d14b53 (diff)
Re-fix "builtin-commit: fix --signoff"
An earlier fix to the said commit was incomplete; it mixed up the meaning of the flag parameter passed to the internal fmt_ident() function, so this corrects it. git_author_info() and git_committer_info() can be told to issue a warning when no usable user information is found, and optionally can be told to error out. Operations that actually use the information to record a new commit or a tag will still error out, but the caller to leave reflog record will just silently use bogus user information. Not warning on misconfigured user information while writing a reflog entry is somewhat debatable, but it is probably nicer to the users to silently let it pass, because the only information you are losing is who checked out the branch. * git_author_info() and git_committer_info() used to take 1 (positive int) to error out with a warning on misconfiguration; this is now signalled with a symbolic constant IDENT_ERROR_ON_NO_NAME. * These functions used to take -1 (negative int) to warn but continue; this is now signalled with a symbolic constant IDENT_WARN_ON_NO_NAME. * fmt_ident() function implements the above error reporting behaviour common to git_author_info() and git_committer_info(). A symbolic constant IDENT_NO_DATE can be or'ed in to the flag parameter to make it return only the "Name <email@address.xz>". * fmt_name() is a thin wrapper around fmt_ident() that always passes IDENT_ERROR_ON_NO_NAME and IDENT_NO_DATE. Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'ident.c')
1 files changed, 12 insertions, 18 deletions
diff --git a/ident.c b/ident.c
index 7631698..892d77a 100644
--- a/ident.c
+++ b/ident.c
@@ -182,14 +182,15 @@ static const char *env_hint =
"Omit --global to set the identity only in this repository.\n"
-static const char *fmt_ident_1(const char *name, const char *email,
- const char *date_str, int flag)
+const char *fmt_ident(const char *name, const char *email,
+ const char *date_str, int flag)
static char buffer[1000];
char date[50];
int i;
- int error_on_no_name = !!(flag & 01);
- int name_addr_only = !!(flag & 02);
+ int error_on_no_name = (flag & IDENT_ERROR_ON_NO_NAME);
+ int warn_on_no_name = (flag & IDENT_WARN_ON_NO_NAME);
+ int name_addr_only = (flag & IDENT_NO_DATE);
if (!name)
@@ -200,12 +201,12 @@ static const char *fmt_ident_1(const char *name, const char *email,
if (!*name) {
struct passwd *pw;
- if (0 <= error_on_no_name &&
+ if ((warn_on_no_name || error_on_no_name) &&
name == git_default_name && env_hint) {
fprintf(stderr, env_hint, au_env, co_env);
env_hint = NULL; /* warn only once, for "git-var -l" */
- if (0 < error_on_no_name)
+ if (error_on_no_name)
die("empty ident %s <%s> not allowed", name, email);
pw = getpwuid(getuid());
if (!pw)
@@ -234,30 +235,23 @@ static const char *fmt_ident_1(const char *name, const char *email,
return buffer;
-const char *fmt_ident(const char *name, const char *email,
- const char *date_str, int error_on_no_name)
- int flag = (error_on_no_name ? 01 : 0);
- return fmt_ident_1(name, email, date_str, flag);
const char *fmt_name(const char *name, const char *email)
- return fmt_ident_1(name, email, NULL, 03);
+ return fmt_ident(name, email, NULL, IDENT_ERROR_ON_NO_NAME | IDENT_NO_DATE);
-const char *git_author_info(int error_on_no_name)
+const char *git_author_info(int flag)
return fmt_ident(getenv("GIT_AUTHOR_NAME"),
- error_on_no_name);
+ flag);
-const char *git_committer_info(int error_on_no_name)
+const char *git_committer_info(int flag)
return fmt_ident(getenv("GIT_COMMITTER_NAME"),
- error_on_no_name);
+ flag);