{"thread":{"id":"24998","subject":"[PATCH] RFC: help.autocorrect prompt","startedAt":"2010-09-06T02:28:26Z","lastAt":"2010-09-06T07:27:10Z","messageCount":4,"participants":["David Barr","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"150027","messageId":"1283740106-11411-1-git-send-email-david.barr@cordelta.com","threadId":"24998","inReplyTo":null,"subject":"[PATCH] RFC: help.autocorrect prompt","fromName":"David Barr","fromEmail":"david.barr@cordelta.com","sentAt":"2010-09-06T02:28:26Z","receivedAt":"2010-09-06T02:28:26Z","isPatch":true,"sender":{"key":"david.barr@cordelta.com","avatar":"https://avatars.githubusercontent.com/u/220594?v=4"},"body":"Added a new configuration value for help.autocorrect.\nA value of 'prompt' causes git to wait for confirmation\nbefore executing the assumed command.\n---\n help.c |   13 ++++++++++---\n 1 files changed, 10 insertions(+), 3 deletions(-)\n\ndiff --git a/help.c b/help.c\nindex 7f4928e..924ce60 100644\n--- a/help.c\n+++ b/help.c\n@@ -267,8 +267,12 @@ static struct cmdnames aliases;\n \n static int git_unknown_cmd_config(const char *var, const char *value, void *cb)\n {\n-\tif (!strcmp(var, \"help.autocorrect\"))\n-\t\tautocorrect = git_config_int(var,value);\n+\tif (!strcmp(var, \"help.autocorrect\")) {\n+\t\tif (!strcmp(value, \"prompt\"))\n+\t\t\tautocorrect = INT_MAX;\n+\t\telse\n+\t\t\tautocorrect = git_config_int(var,value);\n+\t}\n \t/* Also use aliases for command lookup */\n \tif (!prefixcmp(var, \"alias.\"))\n \t\tadd_cmdname(&aliases, var + 6, strlen(var + 6));\n@@ -342,7 +346,10 @@ const char *help_unknown_cmd(const char *cmd)\n \t\t\t\"which does not exist.\\n\"\n \t\t\t\"Continuing under the assumption that you meant '%s'\\n\",\n \t\t\tcmd, assumed);\n-\t\tif (autocorrect > 0) {\n+\t\tif (autocorrect == INT_MAX) {\n+\t\t\tif (strcmp(\"y\", git_getpass(\"Continue? (y/n) \")))\n+\t\t\t\texit(1);\n+\t\t} else if (autocorrect > 0) {\n \t\t\tfprintf(stderr, \"in %0.1f seconds automatically...\\n\",\n \t\t\t\t(float)autocorrect/10.0);\n \t\t\tpoll(NULL, 0, autocorrect * 100);\n-- \n1.7.0.4\n"},{"id":"150028","messageId":"20100906025949.GA23594@burratino","threadId":"24998","inReplyTo":"1283740106-11411-1-git-send-email-david.barr@cordelta.com","subject":"Re: [PATCH] RFC: help.autocorrect prompt","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-09-06T02:59:49Z","receivedAt":"2010-09-06T02:59:49Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"(+cc: Dscho and Heiko)\n\nDavid Barr wrote:\n\n> A value of 'prompt' causes git to wait for confirmation\n> before executing the assumed command.\n\nNice idea.\n\n> ---\n\nSign-off?\n\n> --- a/help.c\n> +++ b/help.c\n> @@ -267,8 +267,12 @@ static struct cmdnames aliases;\n>  \n>  static int git_unknown_cmd_config(const char *var, const char *value, void *cb)\n>  {\n> -\tif (!strcmp(var, \"help.autocorrect\"))\n> -\t\tautocorrect = git_config_int(var,value);\n> +\tif (!strcmp(var, \"help.autocorrect\")) {\n> +\t\tif (!strcmp(value, \"prompt\"))\n> +\t\t\tautocorrect = INT_MAX;\n> +\t\telse\n> +\t\t\tautocorrect = git_config_int(var,value);\n\nAny particular significance to INT_MAX rather than, e.g., -1 here?\n(Just curious; it seems unlikely someone would use INT_MAX and\naccidentally trip on this.)\n\nNot a problem introduced by your patch: should we be checking for\nout-of-range (e.g., negative) values?\n\n> @@ -342,7 +346,10 @@ const char *help_unknown_cmd(const char *cmd)\n>  \t\t\t\"which does not exist.\\n\"\n>  \t\t\t\"Continuing under the assumption that you meant '%s'\\n\",\n>  \t\t\tcmd, assumed);\n> -\t\tif (autocorrect > 0) {\n> +\t\tif (autocorrect == INT_MAX) {\n> +\t\t\tif (strcmp(\"y\", git_getpass(\"Continue? (y/n) \")))\n> +\t\t\t\texit(1);\n\nFunny. :)\n\nIt might be better to actually always write this prompt to the\nterminal, rather than popping up a gui $GIT_ASKPASS if the user has\nset that up.  Maybe something like Heiko Voigt's \"mingw: make failures\nto unlike or move raise a question\" (9229029, 2010-02-21 from\n4msysgit.git):\n\n\tif (!isatty(STDIN_FILENO) || !isatty(STDERR_FILENO))\n\t\texit(1);\n\tfprintf(stderr, \"Continue? (y/n) \");\n\tif (!fgets(answer, sizeof(answer), stdin))\n\t\texit(1)\n\tif (*answer != 'y' && *answer != 'Y')\n\t\texit(1);\n\n> +\t\t} else if (autocorrect > 0) {\n>  \t\t\tfprintf(stderr, \"in %0.1f seconds automatically...\\n\",\n>  \t\t\t\t(float)autocorrect/10.0);\n>  \t\t\tpoll(NULL, 0, autocorrect * 100);\n\nThanks for a pleasant read.\nJonathan\n"},{"id":"150052","messageId":"201009061716.22468.david.barr@cordelta.com","threadId":"24998","inReplyTo":"20100906025949.GA23594@burratino","subject":"Re: [PATCH] RFC: help.autocorrect prompt","fromName":"David Barr","fromEmail":"david.barr@cordelta.com","sentAt":"2010-09-06T07:16:22Z","receivedAt":"2010-09-06T07:16:22Z","isPatch":true,"sender":{"key":"david.barr@cordelta.com","avatar":"https://avatars.githubusercontent.com/u/220594?v=4"},"body":" \n> Any particular significance to INT_MAX rather than, e.g., -1 here?\n> (Just curious; it seems unlikely someone would use INT_MAX and\n> accidentally trip on this.)\n\n> Not a problem introduced by your patch: should we be checking for\n> out-of-range (e.g., negative) values?\n\nThe existing docs say that negative values correspond to immediate execution,\nzero to never, and positive to a delay in deciseconds.\n\nAs noted, I chose INT_MAX as a rather unlikely conscious choice (~7 years).\n\n> > @@ -342,7 +346,10 @@ const char *help_unknown_cmd(const char *cmd)\n> >                       \"which does not exist.\\n\"\n> >                       \"Continuing under the assumption that you meant \n'%s'\\n\",\n> >                       cmd, assumed);\n> > -             if (autocorrect > 0) {\n> > +             if (autocorrect == INT_MAX) {\n> > +                     if (strcmp(\"y\", git_getpass(\"Continue? (y/n) \")))\n> > +                             exit(1);\n> \n> Funny. :)\n> \n> It might be better to actually always write this prompt to the\n> terminal, rather than popping up a gui $GIT_ASKPASS if the user has\n> set that up.  Maybe something like Heiko Voigt's \"mingw: make failures\n> to unlike or move raise a question\" (9229029, 2010-02-21 from\n> 4msysgit.git):\n> \n>         if (!isatty(STDIN_FILENO) || !isatty(STDERR_FILENO))\n>                 exit(1);\n>         fprintf(stderr, \"Continue? (y/n) \");\n>         if (!fgets(answer, sizeof(answer), stdin))\n>                 exit(1)\n>         if (*answer != 'y' && *answer != 'Y')\n>                 exit(1);\n> \n> > +             } else if (autocorrect > 0) {\n> >                       fprintf(stderr, \"in %0.1f seconds automatically...\n\\n\",\n> >                               (float)autocorrect/10.0);\n> >                       poll(NULL, 0, autocorrect * 100);\n\nThat looks much nicer, I was hoping for such a suggestion.\n\n--\nDavid Barr.\n"},{"id":"150053","messageId":"1283758030-13345-1-git-send-email-david.barr@cordelta.com","threadId":"24998","inReplyTo":"20100906025949.GA23594@burratino","subject":"[PATCH] help.autocorrect prompt","fromName":"David Barr","fromEmail":"david.barr@cordelta.com","sentAt":"2010-09-06T07:27:10Z","receivedAt":"2010-09-06T07:27:10Z","isPatch":true,"sender":{"key":"david.barr@cordelta.com","avatar":"https://avatars.githubusercontent.com/u/220594?v=4"},"body":"Added a new configuration value for help.autocorrect.\nA value of 'prompt' causes git to wait for confirmation\nbefore executing the assumed command.\n\nSigned-off-by: David Barr <david.barr@cordelta.com>\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n help.c |   19 ++++++++++++++++---\n 1 files changed, 16 insertions(+), 3 deletions(-)\n\ndiff --git a/help.c b/help.c\nindex 7f4928e..2282885 100644\n--- a/help.c\n+++ b/help.c\n@@ -267,8 +267,12 @@ static struct cmdnames aliases;\n \n static int git_unknown_cmd_config(const char *var, const char *value, void *cb)\n {\n-\tif (!strcmp(var, \"help.autocorrect\"))\n-\t\tautocorrect = git_config_int(var,value);\n+\tif (!strcmp(var, \"help.autocorrect\")) {\n+\t\tif (!strcmp(value, \"prompt\"))\n+\t\t\tautocorrect = INT_MAX;\n+\t\telse\n+\t\t\tautocorrect = git_config_int(var,value);\n+\t}\n \t/* Also use aliases for command lookup */\n \tif (!prefixcmp(var, \"alias.\"))\n \t\tadd_cmdname(&aliases, var + 6, strlen(var + 6));\n@@ -342,7 +346,16 @@ const char *help_unknown_cmd(const char *cmd)\n \t\t\t\"which does not exist.\\n\"\n \t\t\t\"Continuing under the assumption that you meant '%s'\\n\",\n \t\t\tcmd, assumed);\n-\t\tif (autocorrect > 0) {\n+\t\tif (autocorrect == INT_MAX) {\n+\t\t\tchar answer[3];\n+\t\t\tif (!isatty(STDIN_FILENO) || !isatty(STDERR_FILENO))\n+\t\t\t\texit(1);\n+\t\t\tfprintf(stderr, \"Continue? (y/n) \");\n+\t\t\tif (!fgets(answer, sizeof(answer), stdin))\n+\t\t\t\texit(1);\n+\t\t\tif (*answer != 'y' && *answer != 'Y')\n+\t\t\t\texit(1);\n+\t\t} else if (autocorrect > 0) {\n \t\t\tfprintf(stderr, \"in %0.1f seconds automatically...\\n\",\n \t\t\t\t(float)autocorrect/10.0);\n \t\t\tpoll(NULL, 0, autocorrect * 100);\n-- \n1.7.2.3.392.g02377.dirty\n"}]}