{"thread":{"id":"41706","subject":"[PATCH] help.c: strip suffix only if the STRIP_EXTENSION defined","startedAt":"2016-03-16T14:27:29Z","lastAt":"2016-03-16T17:39:41Z","messageCount":6,"participants":["Alexander Kuleshov","Duy Nguyen","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"280902","messageId":"1458138449-26690-1-git-send-email-kuleshovmail@gmail.com","threadId":"41706","inReplyTo":null,"subject":"[PATCH] help.c: strip suffix only if the STRIP_EXTENSION defined","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2016-03-16T14:27:29Z","receivedAt":"2016-03-16T14:27:29Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"We stripping extension in the list_commands_in_dir() to get\ncommands without '.exe' suffix. Let's do it only if STRIP_EXTENSION\nis defined to not spend time for unnecessary strip_suffix() call in\nthis case.\n\nSigned-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n---\n help.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/help.c b/help.c\nindex 19328ea..c865991 100644\n--- a/help.c\n+++ b/help.c\n@@ -153,8 +153,9 @@ static void list_commands_in_dir(struct cmdnames *cmds,\n \t\t\tcontinue;\n \n \t\tentlen = strlen(ent);\n-\t\tstrip_suffix(ent, \".exe\", &entlen);\n-\n+#ifdef STRIP_EXTENSION\n+\t\tstrip_suffix(ent, STRIP_EXTENSION, &entlen);\n+#endif\n \t\tadd_cmdname(cmds, ent, entlen);\n \t}\n \tclosedir(dir);\n-- \n2.8.0.rc2.216.g1477fb2.dirty\n"},{"id":"280904","messageId":"CACsJy8ARrpu=7JJ0=viuNN0pN7wae8FWRN96EqtiH9bOF_vypw@mail.gmail.com","threadId":"41706","inReplyTo":"1458138449-26690-1-git-send-email-kuleshovmail@gmail.com","subject":"Re: [PATCH] help.c: strip suffix only if the STRIP_EXTENSION defined","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2016-03-16T14:47:11Z","receivedAt":"2016-03-16T14:47:11Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, Mar 16, 2016 at 9:27 PM, Alexander Kuleshov\n<kuleshovmail@gmail.com> wrote:\n> We stripping extension in the list_commands_in_dir() to get\n> commands without '.exe' suffix. Let's do it only if STRIP_EXTENSION\n> is defined to not spend time for unnecessary strip_suffix() call in\n> this case.\n\nUnless the time saving is significant, I'm against this change. It\nmakes it harder to spot compile bugs in #ifdef'd code that's only\nactive on Windows (imagine somebody renames \"ent\" or change its type).\nIf you can do something like strip_extension() in git.c, it's better.\nOr maybe just refactor that function a bit and share it with help.c\n\n> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n> ---\n>  help.c | 5 +++--\n>  1 file changed, 3 insertions(+), 2 deletions(-)\n>\n> diff --git a/help.c b/help.c\n> index 19328ea..c865991 100644\n> --- a/help.c\n> +++ b/help.c\n> @@ -153,8 +153,9 @@ static void list_commands_in_dir(struct cmdnames *cmds,\n>                         continue;\n>\n>                 entlen = strlen(ent);\n> -               strip_suffix(ent, \".exe\", &entlen);\n> -\n> +#ifdef STRIP_EXTENSION\n> +               strip_suffix(ent, STRIP_EXTENSION, &entlen);\n> +#endif\n>                 add_cmdname(cmds, ent, entlen);\n>         }\n>         closedir(dir);\n> --\n> 2.8.0.rc2.216.g1477fb2.dirty\n>\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n\n\n\n-- \nDuy\n"},{"id":"280913","messageId":"CANCZXo5m-SF5qHxEgEUSPMaNEkcrZD07qbyfcmMurLVmBDRw+g@mail.gmail.com","threadId":"41706","inReplyTo":"CACsJy8ARrpu=7JJ0=viuNN0pN7wae8FWRN96EqtiH9bOF_vypw@mail.gmail.com","subject":"Re: [PATCH] help.c: strip suffix only if the STRIP_EXTENSION defined","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2016-03-16T16:20:04Z","receivedAt":"2016-03-16T16:20:04Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"On Wed, Mar 16, 2016 at 8:47 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n> On Wed, Mar 16, 2016 at 9:27 PM, Alexander Kuleshov\n> <kuleshovmail@gmail.com> wrote:\n>> We stripping extension in the list_commands_in_dir() to get\n>> commands without '.exe' suffix. Let's do it only if STRIP_EXTENSION\n>> is defined to not spend time for unnecessary strip_suffix() call in\n>> this case.\n>\n> Unless the time saving is significant, I'm against this change. It\n> makes it harder to spot compile bugs in #ifdef'd code that's only\n> active on Windows (imagine somebody renames \"ent\" or change its type).\n> If you can do something like strip_extension() in git.c, it's better.\n> Or maybe just refactor that function a bit and share it with help.c\n\nYes, agree. Will think about this.\n"},{"id":"280928","messageId":"20160316173127.GD4039@sigill.intra.peff.net","threadId":"41706","inReplyTo":"1458138449-26690-1-git-send-email-kuleshovmail@gmail.com","subject":"Re: [PATCH] help.c: strip suffix only if the STRIP_EXTENSION defined","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-03-16T17:31:28Z","receivedAt":"2016-03-16T17:31:28Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Mar 16, 2016 at 08:27:29PM +0600, Alexander Kuleshov wrote:\n\n> We stripping extension in the list_commands_in_dir() to get\n> commands without '.exe' suffix. Let's do it only if STRIP_EXTENSION\n> is defined to not spend time for unnecessary strip_suffix() call in\n> this case.\n> \n> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n> ---\n>  help.c | 5 +++--\n>  1 file changed, 3 insertions(+), 2 deletions(-)\n> \n> diff --git a/help.c b/help.c\n> index 19328ea..c865991 100644\n> --- a/help.c\n> +++ b/help.c\n> @@ -153,8 +153,9 @@ static void list_commands_in_dir(struct cmdnames *cmds,\n>  \t\t\tcontinue;\n>  \n>  \t\tentlen = strlen(ent);\n> -\t\tstrip_suffix(ent, \".exe\", &entlen);\n> -\n> +#ifdef STRIP_EXTENSION\n> +\t\tstrip_suffix(ent, STRIP_EXTENSION, &entlen);\n> +#endif\n\nThis is billed as an optimization in the commit message, but these two\npieces of code are not the same. The original always strips \".exe\",\nwhether or not STRIP_EXTENSION is defined, and whether or not it is\n\".exe\".\n\nIn practice it works out because people on Unix systems do not have\n\"git-foo.exe\", and nobody sets STRIP_EXTENSION to other things.  But I\ntend to think this is an improvement in robustness.\n\nI also wonder if this should be sharing the strip_extension() helper\nadded in your 63ca1c0.\n\n-Peff\n"},{"id":"280930","messageId":"CANCZXo6KGtuuiZ3aha=Tqkwj3d8qytmA_rvw7fPHfevzz9Qyfg@mail.gmail.com","threadId":"41706","inReplyTo":"20160316173127.GD4039@sigill.intra.peff.net","subject":"Re: [PATCH] help.c: strip suffix only if the STRIP_EXTENSION defined","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2016-03-16T17:36:49Z","receivedAt":"2016-03-16T17:36:49Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"Hello Jeff,\n\nOn Wed, Mar 16, 2016 at 11:31 PM, Jeff King <peff@peff.net> wrote:\n> This is billed as an optimization in the commit message, but these two\n> pieces of code are not the same. The original always strips \".exe\",\n> whether or not STRIP_EXTENSION is defined, and whether or not it is\n> \".exe\".\n>\n> In practice it works out because people on Unix systems do not have\n> \"git-foo.exe\", and nobody sets STRIP_EXTENSION to other things.  But I\n> tend to think this is an improvement in robustness.\n>\n> I also wonder if this should be sharing the strip_extension() helper\n> added in your 63ca1c0.\n\nYes, I want to move strip_extension() (from 63ca1c0) to the git-compat-util.h\nand adapt/reuse it in the help.c. What do you think about this?\n\nThank you.\n"},{"id":"280932","messageId":"20160316173941.GA9142@sigill.intra.peff.net","threadId":"41706","inReplyTo":"CANCZXo6KGtuuiZ3aha=Tqkwj3d8qytmA_rvw7fPHfevzz9Qyfg@mail.gmail.com","subject":"Re: [PATCH] help.c: strip suffix only if the STRIP_EXTENSION defined","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-03-16T17:39:41Z","receivedAt":"2016-03-16T17:39:41Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Mar 16, 2016 at 11:36:49PM +0600, Alexander Kuleshov wrote:\n\n> > I also wonder if this should be sharing the strip_extension() helper\n> > added in your 63ca1c0.\n> \n> Yes, I want to move strip_extension() (from 63ca1c0) to the git-compat-util.h\n> and adapt/reuse it in the help.c. What do you think about this?\n\nNaively, it sounds like a good idea to me, but I haven't looked too\nhard. There may be complications in the interface (it looks like the\nhelper wants to make a new string, but one in help.c makes its own copy\ninto the flex-array struct).\n\n-Peff\n"}]}