{"thread":{"id":"3384","subject":"[RFC] empty ident?","startedAt":"2006-02-18T08:44:14Z","lastAt":"2006-02-19T04:56:46Z","messageCount":5,"participants":["Junio C Hamano","Nicolas Vilz 'niv'","Petr Baudis"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"16373","messageId":"7vzmkpqco1.fsf@assigned-by-dhcp.cox.net","threadId":"3384","inReplyTo":null,"subject":"[RFC] empty ident?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-02-18T08:44:14Z","receivedAt":"2006-02-18T08:44:14Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"It appears that some people who did not care about having bogus\nnames in their own commit messages are bitten by the recent\nchange to require a sane environment [*1*].\n\nWhile it was a good idea to prevent people from using bogus\nnames to create commits and doing sign-offs, the error message\nis not very informative.  This patch attempts to warn things\nupfront and hint people how to fix their environments.\n\nLikes, dislikes, don't cares?\n\n[Footnote]\n\n*1* The thread is this one.\n\n    http://marc.theaimsgroup.com/?t=113868084800004\n\n    Especially this message.\n\n    http://marc.theaimsgroup.com/?m=113932830015032\n\n---\ndiff --git a/ident.c b/ident.c\nindex 23b8cfc..09d4d71 100644\n--- a/ident.c\n+++ b/ident.c\n@@ -46,6 +46,15 @@ static void copy_gecos(struct passwd *w,\n \n }\n \n+static const char au_env[] = \"GIT_AUTHOR_NAME\";\n+static const char co_env[] = \"GIT_COMMITTER_NAME\";\n+static const char env_hint[] =\n+\"\\n*** Environment problem:\\n\"\n+\"*** Your name cannot be determined from your system services (gecos).\\n\"\n+\"*** You would need to set %s and %s\\n\"\n+\"*** environment variables; otherwise you won't be able to perform\\n\"\n+\"*** certain operations because of \\\"empty ident\\\" errors.\\n\\n\";\n+\n int setup_ident(void)\n {\n \tint len;\n@@ -57,6 +66,11 @@ int setup_ident(void)\n \t/* Get the name (\"gecos\") */\n \tcopy_gecos(pw, git_default_name, sizeof(git_default_name));\n \n+\tif (!*git_default_name) {\n+\t\tif (!getenv(au_env) || !getenv(co_env))\n+\t\t\tfprintf(stderr, env_hint, au_env, co_env);\n+\t}\n+\n \t/* Make up a fake email address (name + '@' + hostname [+ '.' + domainname]) */\n \tlen = strlen(pw->pw_name);\n \tif (len > sizeof(git_default_email)/2)\n"},{"id":"16377","messageId":"43F6F023.1020708@iaglans.de","threadId":"3384","inReplyTo":"7vzmkpqco1.fsf@assigned-by-dhcp.cox.net","subject":"Re: [RFC] empty ident?","fromName":"Nicolas Vilz 'niv'","fromEmail":"niv@iaglans.de","sentAt":"2006-02-18T10:00:03Z","receivedAt":"2006-02-18T10:00:03Z","isPatch":false,"sender":{"key":"niv@iaglans.de","avatar":"https://gravatar.com/avatar/e4d43a32d721241212d4edb1d2210327e28423c913071b4bfeeaa0ce15296110?d=mp&s=160"},"body":"Junio C Hamano wrote:\n> It appears that some people who did not care about having bogus\n> names in their own commit messages are bitten by the recent\n> change to require a sane environment [*1*].\n> \n> While it was a good idea to prevent people from using bogus\n> names to create commits and doing sign-offs, the error message\n> is not very informative.  This patch attempts to warn things\n> upfront and hint people how to fix their environments.\n\nMh... it made me not using cg-init, but git-init, and after that editing\n.git/config, before the first commit.\n\nThis doesn't apply to works with git-svn, because here imported commits\nare tailored from the base-uuid of the SVN repository and the commit-user.\n\nniv <niv@$uuid>\n\nafter that i can setup my .git/config, as well.\n\nSincerly\nNicolas\n"},{"id":"16390","messageId":"20060218172731.GV31278@pasky.or.cz","threadId":"3384","inReplyTo":"7vzmkpqco1.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] Nice error message for empty idents","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-02-18T17:27:31Z","receivedAt":"2006-02-18T17:27:31Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sat, Feb 18, 2006 at 09:44:14AM CET, I got a letter\nwhere Junio C Hamano <junkio@cox.net> said that...\n> It appears that some people who did not care about having bogus\n> names in their own commit messages are bitten by the recent\n> change to require a sane environment [*1*].\n> \n> While it was a good idea to prevent people from using bogus\n> names to create commits and doing sign-offs, the error message\n> is not very informative.  This patch attempts to warn things\n> upfront and hint people how to fix their environments.\n> \n> Likes, dislikes, don't cares?\n\nOne dislike from me - you shouldn't care if you ain't gonna do it - it\nmakes no sense to require valid gecos if you are never committing\nanything. Note that this \"premature requirement\" plague has already hit\nGIT - come on:\n\n\t$ git-rev-list --help\n\tfatal: Not a git repository\n\nThat's worse than CVS (which allows cvs --help cmd but not cvs cmd\n--help outside of a repository).\n\nI agree that the error message itself is bad.\n\n---\n\n[PATCH] Nice error message for empty idents\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n\n---\ncommit 19b5bda8f0301ed4b856c5cd9137637b89d95d30\ntree 8f91bfd101c32f258c3d8cca467eb7be26d62b91\nparent 8dcc626cd144b2c6eae2a299242bbbe905cb0059\nauthor Petr Baudis <pasky@suse.cz> Sat, 18 Feb 2006 18:26:32 +0100\ncommitter Petr Baudis <xpasky@machine.or.cz> Sat, 18 Feb 2006 18:26:32 +0100\n\n ident.c |    7 ++++---\n 1 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/ident.c b/ident.c\nindex 23b8cfc..c57ba5c 100644\n--- a/ident.c\n+++ b/ident.c\n@@ -168,9 +168,10 @@ static const char *get_ident(const char \n \tif (!email)\n \t\temail = git_default_email;\n \n-\tif (!*name || !*email)\n-\t\tdie(\"empty ident %s <%s> not allowed\",\n-\t\t    name, email);\n+\tif (!*name)\n+\t\tdie(\"empty realname not allowed - please set a realname for your login or use GIT_AUTHOR_NAME\");\n+\tif (!*email)\n+\t\tdie(\"empty email not allowed - please set your GIT_AUTHOR_EMAIL to a non-empty value\");\n \n \tstrcpy(date, git_default_date);\n \tif (date_str)\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nOf the 3 great composers Mozart tells us what it's like to be human,\nBeethoven tells us what it's like to be Beethoven and Bach tells us\nwhat it's like to be the universe.  -- Douglas Adams\n"},{"id":"16392","messageId":"7vpslko5tl.fsf@assigned-by-dhcp.cox.net","threadId":"3384","inReplyTo":"20060218172731.GV31278@pasky.or.cz","subject":"Re: [PATCH] Nice error message for empty idents","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-02-18T18:55:02Z","receivedAt":"2006-02-18T18:55:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Petr Baudis <pasky@suse.cz> writes:\n\n> \t$ git-rev-list --help\n> \tfatal: Not a git repository\n\nHmph, true.  Ideas?\n\n> I agree that the error message itself is bad.\n\n> -\tif (!*name || !*email)\n> -\t\tdie(\"empty ident %s <%s> not allowed\",\n> -\t\t    name, email);\n> +\tif (!*name)\n> +\t\tdie(\"empty realname not allowed - please set a realname for your login or use GIT_AUTHOR_NAME\");\n> +\tif (!*email)\n> +\t\tdie(\"empty email not allowed - please set your GIT_AUTHOR_EMAIL to a non-empty value\");\n\nI've considered doing this, but didn't do it that way, because I\ncould not figure out what to do with GIT_COMMITTER_NAME.  Also\nit might make sense to suggest user.name configuration item in\nthe error/help message.  Ideas?\n"},{"id":"16395","messageId":"7v8xs8lze9.fsf_-_@assigned-by-dhcp.cox.net","threadId":"3384","inReplyTo":"20060218172731.GV31278@pasky.or.cz","subject":"[PATCH] Delay \"empty ident\" errors until they really matter.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-02-19T04:56:46Z","receivedAt":"2006-02-19T04:56:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Previous one warned people upfront to encourage fixing their\nenvironment early, but some people just use repositories and git\ntools read-only without making any changes, and in such a case\nthere is not much point insisting on them having a usable ident.\n\nThis round attempts to move the error until either \"git-var\"\nasks for the ident explicitly or \"commit-tree\" wants to use it.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n  Petr Baudis <pasky@suse.cz> writes:\n\n  > One dislike from me - you shouldn't care if you ain't gonna do it - it\n  > makes no sense to require valid gecos if you are never committing\n  > anything.\n\n  You are absolutely right.  This is to fix the previous one.\n\n cache.h       |    4 ++--\n commit-tree.c |    4 ++--\n ident.c       |   47 +++++++++++++++++++++++++----------------------\n var.c         |    6 +++---\n 4 files changed, 32 insertions(+), 29 deletions(-)\n\n749be728d469e9a0acfdc020feff17c2da510083\ndiff --git a/cache.h b/cache.h\nindex b5db01f..da73fb3 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -246,8 +246,8 @@ void datestamp(char *buf, int bufsize);\n unsigned long approxidate(const char *);\n \n extern int setup_ident(void);\n-extern const char *git_author_info(void);\n-extern const char *git_committer_info(void);\n+extern const char *git_author_info(int);\n+extern const char *git_committer_info(int);\n \n struct checkout {\n \tconst char *base_dir;\ndiff --git a/commit-tree.c b/commit-tree.c\nindex b1c8dca..88871b0 100644\n--- a/commit-tree.c\n+++ b/commit-tree.c\n@@ -118,8 +118,8 @@ int main(int argc, char **argv)\n \t\tadd_buffer(&buffer, &size, \"parent %s\\n\", sha1_to_hex(parent_sha1[i]));\n \n \t/* Person/date information */\n-\tadd_buffer(&buffer, &size, \"author %s\\n\", git_author_info());\n-\tadd_buffer(&buffer, &size, \"committer %s\\n\\n\", git_committer_info());\n+\tadd_buffer(&buffer, &size, \"author %s\\n\", git_author_info(1));\n+\tadd_buffer(&buffer, &size, \"committer %s\\n\\n\", git_committer_info(1));\n \n \t/* And add the comment */\n \twhile (fgets(comment, sizeof(comment), stdin) != NULL)\ndiff --git a/ident.c b/ident.c\nindex 09d4d71..7c81fe8 100644\n--- a/ident.c\n+++ b/ident.c\n@@ -46,15 +46,6 @@ static void copy_gecos(struct passwd *w,\n \n }\n \n-static const char au_env[] = \"GIT_AUTHOR_NAME\";\n-static const char co_env[] = \"GIT_COMMITTER_NAME\";\n-static const char env_hint[] =\n-\"\\n*** Environment problem:\\n\"\n-\"*** Your name cannot be determined from your system services (gecos).\\n\"\n-\"*** You would need to set %s and %s\\n\"\n-\"*** environment variables; otherwise you won't be able to perform\\n\"\n-\"*** certain operations because of \\\"empty ident\\\" errors.\\n\\n\";\n-\n int setup_ident(void)\n {\n \tint len;\n@@ -66,11 +57,6 @@ int setup_ident(void)\n \t/* Get the name (\"gecos\") */\n \tcopy_gecos(pw, git_default_name, sizeof(git_default_name));\n \n-\tif (!*git_default_name) {\n-\t\tif (!getenv(au_env) || !getenv(co_env))\n-\t\t\tfprintf(stderr, env_hint, au_env, co_env);\n-\t}\n-\n \t/* Make up a fake email address (name + '@' + hostname [+ '.' + domainname]) */\n \tlen = strlen(pw->pw_name);\n \tif (len > sizeof(git_default_email)/2)\n@@ -170,8 +156,18 @@ static int copy(char *buf, int size, int\n \treturn offset;\n }\n \n+static const char au_env[] = \"GIT_AUTHOR_NAME\";\n+static const char co_env[] = \"GIT_COMMITTER_NAME\";\n+static const char *env_hint =\n+\"\\n*** Environment problem:\\n\"\n+\"*** Your name cannot be determined from your system services (gecos).\\n\"\n+\"*** You would need to set %s and %s\\n\"\n+\"*** environment variables; otherwise you won't be able to perform\\n\"\n+\"*** certain operations because of \\\"empty ident\\\" errors.\\n\"\n+\"*** Alternatively, you can use user.name configuration variable.\\n\\n\";\n+\n static const char *get_ident(const char *name, const char *email,\n-\t\t\t     const char *date_str)\n+\t\t\t     const char *date_str, int error_on_no_name)\n {\n \tstatic char buffer[1000];\n \tchar date[50];\n@@ -182,9 +178,14 @@ static const char *get_ident(const char \n \tif (!email)\n \t\temail = git_default_email;\n \n-\tif (!*name || !*email)\n-\t\tdie(\"empty ident %s <%s> not allowed\",\n-\t\t    name, email);\n+\tif (!*name) {\n+\t\tif (name == git_default_name && env_hint) {\n+\t\t\tfprintf(stderr, env_hint, au_env, co_env);\n+\t\t\tenv_hint = NULL; /* warn only once, for \"git-var -l\" */\n+\t\t}\n+\t\tif (error_on_no_name)\n+\t\t\tdie(\"empty ident %s <%s> not allowed\", name, email);\n+\t}\n \n \tstrcpy(date, git_default_date);\n \tif (date_str)\n@@ -201,16 +202,18 @@ static const char *get_ident(const char \n \treturn buffer;\n }\n \n-const char *git_author_info(void)\n+const char *git_author_info(int error_on_no_name)\n {\n \treturn get_ident(getenv(\"GIT_AUTHOR_NAME\"),\n \t\t\t getenv(\"GIT_AUTHOR_EMAIL\"),\n-\t\t\t getenv(\"GIT_AUTHOR_DATE\"));\n+\t\t\t getenv(\"GIT_AUTHOR_DATE\"),\n+\t\t\t error_on_no_name);\n }\n \n-const char *git_committer_info(void)\n+const char *git_committer_info(int error_on_no_name)\n {\n \treturn get_ident(getenv(\"GIT_COMMITTER_NAME\"),\n \t\t\t getenv(\"GIT_COMMITTER_EMAIL\"),\n-\t\t\t getenv(\"GIT_COMMITTER_DATE\"));\n+\t\t\t getenv(\"GIT_COMMITTER_DATE\"),\n+\t\t\t error_on_no_name);\n }\ndiff --git a/var.c b/var.c\nindex 59da56d..a57a33b 100644\n--- a/var.c\n+++ b/var.c\n@@ -12,7 +12,7 @@ static const char var_usage[] = \"git-var\n \n struct git_var {\n \tconst char *name;\n-\tconst char *(*read)(void);\n+\tconst char *(*read)(int);\n };\n static struct git_var git_vars[] = {\n \t{ \"GIT_COMMITTER_IDENT\", git_committer_info },\n@@ -24,7 +24,7 @@ static void list_vars(void)\n {\n \tstruct git_var *ptr;\n \tfor(ptr = git_vars; ptr->read; ptr++) {\n-\t\tprintf(\"%s=%s\\n\", ptr->name, ptr->read());\n+\t\tprintf(\"%s=%s\\n\", ptr->name, ptr->read(0));\n \t}\n }\n \n@@ -35,7 +35,7 @@ static const char *read_var(const char *\n \tval = NULL;\n \tfor(ptr = git_vars; ptr->read; ptr++) {\n \t\tif (strcmp(var, ptr->name) == 0) {\n-\t\t\tval = ptr->read();\n+\t\t\tval = ptr->read(1);\n \t\t\tbreak;\n \t\t}\n \t}\n-- \n1.2.1.g2902\n"}]}