{"thread":{"id":"31400","subject":"[PATCH] split_ident_line(): make best effort when parsing author/committer line","startedAt":"2012-08-31T21:57:16Z","lastAt":"2012-08-31T21:57:16Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"198172","messageId":"7vwr0elo77.fsf@alter.siamese.dyndns.org","threadId":"31400","inReplyTo":null,"subject":"[PATCH] split_ident_line(): make best effort when parsing author/committer line","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-08-31T21:57:16Z","receivedAt":"2012-08-31T21:57:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Commits made by ancient version of Git allowed committer without\nhuman readable name, like this (00213b17c in the kernel history):\n\n    tree 6947dba41f8b0e7fe7bccd41a4840d6de6a27079\n    parent 352dd1df32e672be4cff71132eb9c06a257872fe\n    author Petr Baudis <pasky@ucw.cz> 1135223044 +0100\n    committer  <sam@mars.ravnborg.org> 1136151043 +0100\n\n    kconfig: Remove support for lxdialog --checklist\n\n    ...\n\n    Signed-off-by: Petr Baudis <pasky@suse.cz>\n    Signed-off-by: Sam Ravnborg <sam@ravnborg.org>\n\nWhen fed such a commit, --format='%ci' fails to parse it, and gives\nback an empty string.  Update the split_ident_line() to be a bit\nmore lenient when parsing, but make sure the caller that wants to\npick up sane value from its return value does its own validation.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/commit.c | 17 ++++++++++++++++-\n ident.c          |  6 ++++--\n 2 files changed, 20 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 20cef95..62028e7 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -478,6 +478,20 @@ static void export_one(const char *var, const char *s, const char *e, int hack)\n \tstrbuf_release(&buf);\n }\n \n+static int sane_ident_split(struct ident_split *person)\n+{\n+\tif (!person->name_begin || !person->name_end ||\n+\t    person->name_begin == person->name_end)\n+\t\treturn 0; /* no human readable name */\n+\tif (!person->mail_begin || !person->mail_end ||\n+\t    person->mail_begin == person->mail_end)\n+\t\treturn 0; /* no usable mail */\n+\tif (!person->date_begin || !person->date_end ||\n+\t    !person->tz_begin || !person->tz_end)\n+\t\treturn 0;\n+\treturn 1;\n+}\n+\n static void determine_author_info(struct strbuf *author_ident)\n {\n \tchar *name, *email, *date;\n@@ -530,7 +544,8 @@ static void determine_author_info(struct strbuf *author_ident)\n \tif (force_date)\n \t\tdate = force_date;\n \tstrbuf_addstr(author_ident, fmt_ident(name, email, date, IDENT_STRICT));\n-\tif (!split_ident_line(&author, author_ident->buf, author_ident->len)) {\n+\tif (!split_ident_line(&author, author_ident->buf, author_ident->len) &&\n+\t    sane_ident_split(&author)) {\n \t\texport_one(\"GIT_AUTHOR_NAME\", author.name_begin, author.name_end, 0);\n \t\texport_one(\"GIT_AUTHOR_EMAIL\", author.mail_begin, author.mail_end, 0);\n \t\texport_one(\"GIT_AUTHOR_DATE\", author.date_begin, author.tz_end, '@');\ndiff --git a/ident.c b/ident.c\nindex 443c075..484e0a9 100644\n--- a/ident.c\n+++ b/ident.c\n@@ -210,8 +210,10 @@ int split_ident_line(struct ident_split *split, const char *line, int len)\n \t\t\tsplit->name_end = cp + 1;\n \t\t\tbreak;\n \t\t}\n-\tif (!split->name_end)\n-\t\treturn status;\n+\tif (!split->name_end) {\n+\t\t/* no human readable name */\n+\t\tsplit->name_end = split->name_begin;\n+\t}\n \n \tfor (cp = split->mail_begin; cp < line + len; cp++)\n \t\tif (*cp == '>') {\n-- \n1.7.12.298.gee11d52\n"}]}