{"thread":{"id":"11184","subject":"[PATCH 1/2] mailmap: fix bogus for() loop that happened to be safe by accident","startedAt":"2007-12-08T01:32:52Z","lastAt":"2007-12-08T17:13:14Z","messageCount":4,"participants":["Junio C Hamano","Wincent Colaiuta","Alex Riesen"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"62353","messageId":"1197077573-14945-1-git-send-email-gitster@pobox.com","threadId":"11184","inReplyTo":null,"subject":"[PATCH 1/2] mailmap: fix bogus for() loop that happened to be safe by accident","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-08T01:32:52Z","receivedAt":"2007-12-08T01:32:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The empty loop pretended to have an empty statement as its body by a\nphony indentation, but in fact was slurping the next statement into it.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n mailmap.c |    7 ++++---\n 1 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/mailmap.c b/mailmap.c\nindex 8714167..f017255 100644\n--- a/mailmap.c\n+++ b/mailmap.c\n@@ -42,9 +42,10 @@ int read_mailmap(struct path_list *map, const char *filename, char **repo_abbrev\n \t\t\tcontinue;\n \t\tif (right_bracket == left_bracket + 1)\n \t\t\tcontinue;\n-\t\tfor (end_of_name = left_bracket; end_of_name != buffer\n-\t\t\t\t&& isspace(end_of_name[-1]); end_of_name--)\n-\t\t\t/* keep on looking */\n+\t\tfor (end_of_name = left_bracket;\n+\t\t     end_of_name != buffer && isspace(end_of_name[-1]);\n+\t\t     end_of_name--)\n+\t\t\t; /* keep on looking */\n \t\tif (end_of_name == buffer)\n \t\t\tcontinue;\n \t\tname = xmalloc(end_of_name - buffer + 1);\n-- \n1.5.3.7-2182-g108b\n"},{"id":"62354","messageId":"1197077573-14945-2-git-send-email-gitster@pobox.com","threadId":"11184","inReplyTo":"1197077573-14945-1-git-send-email-gitster@pobox.com","subject":"[PATCH 2/2] shortlog: code restruturing and clean-up","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-08T01:32:53Z","receivedAt":"2007-12-08T01:32:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The code tried to parse and clean-up the author name and the one line\ninformation in three places (two callers of insert_author_oneline() and\nthe called function itself), whihc was a mess.\n\nThis renames the callee to insert_one_record() and make it responsible\nfor cleaning up the author name and one line information.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin-shortlog.c |  165 +++++++++++++++++++--------------------------------\n 1 files changed, 62 insertions(+), 103 deletions(-)\n\ndiff --git a/builtin-shortlog.c b/builtin-shortlog.c\nindex 3fe7546..b9cc134 100644\n--- a/builtin-shortlog.c\n+++ b/builtin-shortlog.c\n@@ -27,45 +27,60 @@ static int compare_by_number(const void *a1, const void *a2)\n \n static struct path_list mailmap = {NULL, 0, 0, 0};\n \n-static void insert_author_oneline(struct path_list *list,\n-\t\tconst char *author, int authorlen,\n-\t\tconst char *oneline, int onelinelen)\n+static void insert_one_record(struct path_list *list,\n+\t\t\t      const char *author,\n+\t\t\t      const char *oneline)\n {\n \tconst char *dot3 = common_repo_prefix;\n \tchar *buffer, *p;\n \tstruct path_list_item *item;\n \tstruct path_list *onelines;\n+\tchar namebuf[1024];\n+\tsize_t len;\n+\tconst char *eol;\n+\tconst char *boemail, *eoemail;\n+\n+\tboemail = strchr(author, '<');\n+\tif (!boemail)\n+\t\treturn;\n+\teoemail = strchr(boemail, '>');\n+\tif (!eoemail)\n+\t\treturn;\n+\tif (!map_email(&mailmap, boemail+1, namebuf, sizeof(namebuf))) {\n+\t\twhile (author < boemail && isspace(*author))\n+\t\t\tauthor++;\n+\t\tfor (len = 0;\n+\t\t     len < sizeof(namebuf) - 1 && author + len < boemail;\n+\t\t     len++)\n+\t\t\tnamebuf[len] = author[len];\n+\t\twhile (0 < len && isspace(namebuf[len-1]))\n+\t\t\tlen--;\n+\t\tnamebuf[len] = '\\0';\n+\t}\n \n-\twhile (authorlen > 0 && isspace(author[authorlen - 1]))\n-\t\tauthorlen--;\n-\n-\tbuffer = xmemdupz(author, authorlen);\n+\tbuffer = xstrdup(namebuf);\n \titem = path_list_insert(buffer, list);\n \tif (item->util == NULL)\n \t\titem->util = xcalloc(1, sizeof(struct path_list));\n \telse\n \t\tfree(buffer);\n \n+\teol = strchr(oneline, '\\n');\n+\tif (!eol)\n+\t\teol = oneline + strlen(oneline);\n+\twhile (*oneline && isspace(*oneline) && *oneline != '\\n')\n+\t\toneline++;\n \tif (!prefixcmp(oneline, \"[PATCH\")) {\n \t\tchar *eob = strchr(oneline, ']');\n-\n-\t\tif (eob) {\n-\t\t\twhile (isspace(eob[1]) && eob[1] != '\\n')\n-\t\t\t\teob++;\n-\t\t\tif (eob - oneline < onelinelen) {\n-\t\t\t\tonelinelen -= eob - oneline;\n-\t\t\t\toneline = eob;\n-\t\t\t}\n-\t\t}\n+\t\tif (eob && (!eol || eob < eol))\n+\t\t\toneline = eob + 1;\n \t}\n-\n-\twhile (onelinelen > 0 && isspace(oneline[0])) {\n+\twhile (*oneline && isspace(*oneline) && *oneline != '\\n')\n \t\toneline++;\n-\t\tonelinelen--;\n-\t}\n-\twhile (onelinelen > 0 && isspace(oneline[onelinelen - 1]))\n-\t\tonelinelen--;\n-\tbuffer = xmemdupz(oneline, onelinelen);\n+\tlen = eol - oneline;\n+\twhile (len && isspace(oneline[len-1]))\n+\t\tlen--;\n+\tbuffer = xmemdupz(oneline, len);\n \n \tif (dot3) {\n \t\tint dot3len = strlen(dot3);\n@@ -92,55 +107,32 @@ static void insert_author_oneline(struct path_list *list,\n \n static void read_from_stdin(struct path_list *list)\n {\n-\tchar buffer[1024];\n-\n-\twhile (fgets(buffer, sizeof(buffer), stdin) != NULL) {\n-\t\tchar *bob;\n-\t\tif ((buffer[0] == 'A' || buffer[0] == 'a') &&\n-\t\t\t\t!prefixcmp(buffer + 1, \"uthor: \") &&\n-\t\t\t\t(bob = strchr(buffer + 7, '<')) != NULL) {\n-\t\t\tchar buffer2[1024], offset = 0;\n-\n-\t\t\tif (map_email(&mailmap, bob + 1, buffer, sizeof(buffer)))\n-\t\t\t\tbob = buffer + strlen(buffer);\n-\t\t\telse {\n-\t\t\t\toffset = 8;\n-\t\t\t\twhile (buffer + offset < bob &&\n-\t\t\t\t       isspace(bob[-1]))\n-\t\t\t\t\tbob--;\n-\t\t\t}\n-\n-\t\t\twhile (fgets(buffer2, sizeof(buffer2), stdin) &&\n-\t\t\t\t\tbuffer2[0] != '\\n')\n-\t\t\t\t; /* chomp input */\n-\t\t\tif (fgets(buffer2, sizeof(buffer2), stdin)) {\n-\t\t\t\tint l2 = strlen(buffer2);\n-\t\t\t\tint i;\n-\t\t\t\tfor (i = 0; i < l2; i++)\n-\t\t\t\t\tif (!isspace(buffer2[i]))\n-\t\t\t\t\t\tbreak;\n-\t\t\t\tinsert_author_oneline(list,\n-\t\t\t\t\t\tbuffer + offset,\n-\t\t\t\t\t\tbob - buffer - offset,\n-\t\t\t\t\t\tbuffer2 + i, l2 - i);\n-\t\t\t}\n-\t\t}\n+\tchar author[1024], oneline[1024];\n+\n+\twhile (fgets(author, sizeof(author), stdin) != NULL) {\n+\t\tif (!(author[0] == 'A' || author[0] == 'a') ||\n+\t\t    prefixcmp(author + 1, \"uthor: \"))\n+\t\t\tcontinue;\n+\t\twhile (fgets(oneline, sizeof(oneline), stdin) &&\n+\t\t       oneline[0] != '\\n')\n+\t\t\t; /* discard headers */\n+\t\twhile (fgets(oneline, sizeof(oneline), stdin) &&\n+\t\t       oneline[0] == '\\n')\n+\t\t\t; /* discard blanks */\n+\t\tinsert_one_record(list, author + 8, oneline);\n \t}\n }\n \n static void get_from_rev(struct rev_info *rev, struct path_list *list)\n {\n-\tchar scratch[1024];\n \tstruct commit *commit;\n \n \tprepare_revision_walk(rev);\n \twhile ((commit = get_revision(rev)) != NULL) {\n-\t\tconst char *author = NULL, *oneline, *buffer;\n-\t\tint authorlen = authorlen, onelinelen;\n+\t\tconst char *author = NULL, *buffer;\n \n-\t\t/* get author and oneline */\n-\t\tfor (buffer = commit->buffer; buffer && *buffer != '\\0' &&\n-\t\t\t\t*buffer != '\\n'; ) {\n+\t\tbuffer = commit->buffer;\n+\t\twhile (*buffer && *buffer != '\\n') {\n \t\t\tconst char *eol = strchr(buffer, '\\n');\n \n \t\t\tif (eol == NULL)\n@@ -148,50 +140,17 @@ static void get_from_rev(struct rev_info *rev, struct path_list *list)\n \t\t\telse\n \t\t\t\teol++;\n \n-\t\t\tif (!prefixcmp(buffer, \"author \")) {\n-\t\t\t\tchar *bracket = strchr(buffer, '<');\n-\n-\t\t\t\tif (bracket == NULL || bracket > eol)\n-\t\t\t\t\tdie(\"Invalid commit buffer: %s\",\n-\t\t\t\t\t    sha1_to_hex(commit->object.sha1));\n-\n-\t\t\t\tif (map_email(&mailmap, bracket + 1, scratch,\n-\t\t\t\t\t\t\tsizeof(scratch))) {\n-\t\t\t\t\tauthor = scratch;\n-\t\t\t\t\tauthorlen = strlen(scratch);\n-\t\t\t\t} else {\n-\t\t\t\t\tif (bracket[-1] == ' ')\n-\t\t\t\t\t\tbracket--;\n-\n-\t\t\t\t\tauthor = buffer + 7;\n-\t\t\t\t\tauthorlen = bracket - buffer - 7;\n-\t\t\t\t}\n-\t\t\t}\n+\t\t\tif (!prefixcmp(buffer, \"author \"))\n+\t\t\t\tauthor = buffer + 7;\n \t\t\tbuffer = eol;\n \t\t}\n-\n-\t\tif (author == NULL)\n-\t\t\tdie (\"Missing author: %s\",\n-\t\t\t\t\tsha1_to_hex(commit->object.sha1));\n-\n-\t\tif (buffer == NULL || *buffer == '\\0') {\n-\t\t\toneline = \"<none>\";\n-\t\t\tonelinelen = sizeof(oneline) + 1;\n-\t\t} else {\n-\t\t\tchar *eol;\n-\n-\t\t\toneline = buffer + 1;\n-\t\t\teol = strchr(oneline, '\\n');\n-\t\t\tif (eol == NULL)\n-\t\t\t\tonelinelen = strlen(oneline);\n-\t\t\telse\n-\t\t\t\tonelinelen = eol - oneline;\n-\t\t}\n-\n-\t\tinsert_author_oneline(list,\n-\t\t\t\tauthor, authorlen, oneline, onelinelen);\n+\t\tif (!author)\n+\t\t\tdie(\"Missing author: %s\",\n+\t\t\t    sha1_to_hex(commit->object.sha1));\n+\t\tif (*buffer)\n+\t\t\tbuffer++;\n+\t\tinsert_one_record(list, author, !*buffer ? \"<none>\" : buffer);\n \t}\n-\n }\n \n static int parse_uint(char const **arg, int comma)\n-- \n1.5.3.7-2182-g108b\n"},{"id":"62396","messageId":"BDA543BC-4D4E-4718-BC29-B4317C44EB90@wincent.com","threadId":"11184","inReplyTo":"1197077573-14945-2-git-send-email-gitster@pobox.com","subject":"Re: [PATCH 2/2] shortlog: code restruturing and clean-up","fromName":"Wincent Colaiuta","fromEmail":"win@wincent.com","sentAt":"2007-12-08T09:34:39Z","receivedAt":"2007-12-08T09:34:39Z","isPatch":true,"sender":{"key":"greg@hurrell.net","avatar":"https://avatars.githubusercontent.com/u/7074?v=4"},"body":"El 8/12/2007, a las 2:32, Junio C Hamano escribió:\n\n> The code tried to parse and clean-up the author name and the one line\n> information in three places (two callers of insert_author_oneline()  \n> and\n> the called function itself), whihc was a mess.\n\nwhihc -> which\n\nCheers,\nWincent\n"},{"id":"62421","messageId":"20071208171314.GA2812@steel.home","threadId":"11184","inReplyTo":"1197077573-14945-2-git-send-email-gitster@pobox.com","subject":"Re: [PATCH 2/2] shortlog: code restruturing and clean-up","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-12-08T17:13:14Z","receivedAt":"2007-12-08T17:13:14Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Junio C Hamano, Sat, Dec 08, 2007 02:32:53 +0100:\n> Subject: Re: [PATCH 2/2] shortlog: code restruturing and clean-up\n\nrestruturing -> restructuring\n"}]}