{"thread":{"id":"47540","subject":"Patch recommendation for replace invoke of error() to that of error_errno()","startedAt":"2018-01-05T03:23:47Z","lastAt":"2018-01-30T22:11:15Z","messageCount":4,"participants":["牛旭","Jeff King","Stefan Beller"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"335901","messageId":"950adae.6741.160c458ce64.Coremail.niuxu16@nudt.edu.cn","threadId":"47540","inReplyTo":null,"subject":"Patch recommendation for replace invoke of error() to that of error_errno()","fromName":"牛旭","fromEmail":"niuxu16@nudt.edu.cn","sentAt":"2018-01-05T03:24:02Z","receivedAt":"2018-01-05T03:23:47Z","isPatch":false,"sender":{"key":"niuxu16@nudt.edu.cn","avatar":null},"body":"Our team researches on consistent update of Git during evolution. And we have figured out several spots that may be missed. \n\n\nBy mining historical patches, we suggest that invokes of error(..., strerror(errno)) should be replaced with that of error_errno(). One example for recommendation and corresponding patch are listed as follows. \n\nOne example of missed spot:\n\n1  int cmd_fetch__tool(int argc, const char **argv, const char \n  *prefix)\n2  {\n....\n31  filename = git_path_fetch_head();\n32  fp = fopen(filename, \"a\");\n33  if (!fp)\n34  return error(\"cannot open %s: %s\", filename, strerror(errno));\n....\n  }\n\nOne example of historical patch:\n1  if (!strcmp(*paths, \"-\"))\n2  in = stdin;\n3  else\n4  in = fopen(*paths, \"r\");\n5\n6  if (!in)\n7  -  return error(_(\"could not open '%s' for reading: %s\"),\n8  -     *paths, strerror(errno));\n9  +  return error_errno(_(\"could not open '%s' for reading\"),\n10 +     *paths);\n11\n12 mail = mkpath(\"%s/%0*d\", state->dir, state->prec, i + 1);\n13\n14 out = fopen(mail, \"w\");\n15 if (!out)\n16 - return error(_(\"could not open '%s' for writing: %s\"),\n17 - mail, strerror(errno));\n18 + return error_errno(_(\"could not open '%s' for writing\"),\n19 + mail);\n20\n21 ret = fn(out, in, keep_cr);\n22\n23 fclose(out);\n24 fclose(in);\n25\nMore recommendations and supporting patches are saved in attachments. It is so kind of you to reply me about the correctness of our suggestions. And thank you for your reading. "},{"id":"335910","messageId":"20180105070409.GA14251@sigill.intra.peff.net","threadId":"47540","inReplyTo":"950adae.6741.160c458ce64.Coremail.niuxu16@nudt.edu.cn","subject":"Re: Patch recommendation for replace invoke of error() to that of error_errno()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-01-05T07:04:10Z","receivedAt":"2018-01-05T07:04:17Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Jan 05, 2018 at 11:24:02AM +0800, 牛旭 wrote:\n\n> Our team researches on consistent update of Git during evolution. And\n> we have figured out several spots that may be missed. \n> \n> \n> By mining historical patches, we suggest that invokes of error(...,\n> strerror(errno)) should be replaced with that of error_errno(). One\n> example for recommendation and corresponding patch are listed as\n> follows. \n\nYes, historically we've done cleanups like this across time as we touch\nthe various pieces of code. More conversions are welcome as long as they\ndon't conflict with any topics that other people are working on (a good\ntest is to see if your suggested changes merge cleanly with the \"pu\"\nbranch).\n\nIn more recent times, we've been using the Coccinelle tool to do\nautomated conversions across the code base. Look at the contents and\nhistory of the contrib/coccinelle directory. This might be a candidate\nfor that cleanup.\n\n> One example of missed spot:\n> \n> 1  int cmd_fetch__tool(int argc, const char **argv, const char \n>   *prefix)\n> 2  {\n> ....\n> 31  filename = git_path_fetch_head();\n> 32  fp = fopen(filename, \"a\");\n> 33  if (!fp)\n> 34  return error(\"cannot open %s: %s\", filename, strerror(errno));\n> ....\n>   }\n\nThis one is actually a bit funny. It's in contrib/examples, which is all\nhistorical code. It's not compiled or used as part of Git (and I'd\nsuspect most of it would not compile at all these days). It's not really\nworth modernizing.\n\n> More recommendations and supporting patches are saved in attachments.\n> It is so kind of you to reply me about the correctness of our\n> suggestions. And thank you for your reading. \n\nEek, word documents. We're happy to take patches, but please format them\nas plain text in your email (e.g., by using git-send-email). More\ndetails are in Documentation/SubmittingPatches. Thanks.\n\n-Peff\n"},{"id":"337609","messageId":"63a7d2b3.8dd7.1613d72ec2f.Coremail.niuxu16@nudt.edu.cn","threadId":"47540","inReplyTo":"950adae.6741.160c458ce64.Coremail.niuxu16@nudt.edu.cn","subject":"recommendations for log enhancement","fromName":"牛旭","fromEmail":"niuxu16@nudt.edu.cn","sentAt":"2018-01-28T15:46:37Z","receivedAt":"2018-01-28T15:46:15Z","isPatch":false,"sender":{"key":"niuxu16@nudt.edu.cn","avatar":null},"body":"Our team studies the consistent edits of git during evolution. And we find several missed edits in the latest release of git. For example, there are two consist edits we have figured out from historical commits:\n1) . Version: git 2.3.9 – git-2.3.10\n       File: builtin/merge-tree.c\n\n \tdst.size = size;\n-\txdi_diff(&src, &dst, &xpp, &xecfg, &ecb);\n+\tif (xdi_diff(&src, &dst, &xpp, &xecfg, &ecb))\n+\t\tdie(\"unable to generate diff\");\n \tfree(src.ptr);\n \tfree(dst.ptr);\n }\n\n2) .Version: git 2.3.9 – git-2.3.10\n      File: combine-diff.c\n  \n-\txdi_diff_outf(&parent_file, result_file, consume_line, &state,\n-\t\t      &xpp, &xecfg);\n+\tif (xdi_diff_outf(&parent_file, result_file, consume_line, &state,\n+\t\t\t  &xpp, &xecfg))\n+\t\tdie(\"unable to generate combined diff for %s\",\n+\t\t    sha1_to_hex(parent));\n \tfree(parent_file.ptr);\n\nThose two commits both add if structure and log messages for handling the return value of xdi_diff_outf(). \nAnd in the latest release, we find one candidate that may also need log statements inserted:\n1)  File: git-2.14.2/builtin/rerere.c\n    \n     1\tstatic int diff_two(const char *file1, const char *label1,\n     2\t\t\tconst char *file2, const char *label2)\n     3\t{\n….\n    20\t\tret = xdi_diff(&minus, &plus, &xpp, &xecfg, &ecb);\n    21\t\n    22\t\tfree(minus.ptr);\n    23\t\tfree(plus.ptr);\n    24\t\treturn ret;\n    25\t}\n...\n}\n\nThere are more examples of consistent update and corresponding suggestions in attachment. It is so nice of you to read them and share me with your opinion on the correctness of our suggestion. Thanks a lot. "},{"id":"337848","messageId":"CAGZ79kbYgTVw0LH6w14Ho_g0yy7XBLhoZO_vP71GHYf4JdmfYA@mail.gmail.com","threadId":"47540","inReplyTo":"63a7d2b3.8dd7.1613d72ec2f.Coremail.niuxu16@nudt.edu.cn","subject":"Re: recommendations for log enhancement","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-01-30T22:11:06Z","receivedAt":"2018-01-30T22:11:15Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Sun, Jan 28, 2018 at 7:46 AM, 牛旭 <niuxu16@nudt.edu.cn> wrote:\n> Our team studies the consistent edits of git during evolution. And we find several missed edits in the latest release of git. For example, there are two consist edits we have figured out from historical commits:\n\nThanks for studying the code of Git. It will help the project in\nbettering the code.\nWelcome to the Git community!\nWhich version do you mean by \"latest release\" ?\n\n\n> 1) . Version: git 2.3.9 – git-2.3.10\n>        File: builtin/merge-tree.c\n>\n>         dst.size = size;\n> -       xdi_diff(&src, &dst, &xpp, &xecfg, &ecb);\n> +       if (xdi_diff(&src, &dst, &xpp, &xecfg, &ecb))\n> +               die(\"unable to generate diff\");\n>         free(src.ptr);\n>         free(dst.ptr);\n>  }\n>\n> 2) .Version: git 2.3.9 – git-2.3.10\n>       File: combine-diff.c\n>\n> -       xdi_diff_outf(&parent_file, result_file, consume_line, &state,\n> -                     &xpp, &xecfg);\n> +       if (xdi_diff_outf(&parent_file, result_file, consume_line, &state,\n> +                         &xpp, &xecfg))\n> +               die(\"unable to generate combined diff for %s\",\n> +                   sha1_to_hex(parent));\n>         free(parent_file.ptr);\n>\n> Those two commits both add if structure and log messages for handling the return value of xdi_diff_outf().\n> And in the latest release, we find one candidate that may also need log statements inserted:\n> 1)  File: git-2.14.2/builtin/rerere.c\n>\n>      1  static int diff_two(const char *file1, const char *label1,\n>      2                  const char *file2, const char *label2)\n>      3  {\n> ….\n>     20          ret = xdi_diff(&minus, &plus, &xpp, &xecfg, &ecb);\n>     21\n>     22          free(minus.ptr);\n>     23          free(plus.ptr);\n>     24          return ret;\n>     25  }\n> ...\n> }\n>\n> There are more examples of consistent update and corresponding suggestions in attachment. It is so nice of you to read them and share me with your opinion on the correctness of our suggestion. Thanks a lot.\n\nThanks a lot for this suggestion and the suggestions in the attachment.\n\nHowever these are less than optimal to consume for the project.\nCare to make these changes as actual commits in your local repository\nand then send patches?\n\nSee Documentation/SubmittingPatches\nhttps://github.com/git/git/blob/master/Documentation/SubmittingPatches\n\nThanks,\nStefan\n"}]}