{"thread":{"id":"24882","subject":"[PATCH] shell: Display errors from improperly-formatted command lines","startedAt":"2010-08-27T05:36:13Z","lastAt":"2010-08-27T17:32:05Z","messageCount":3,"participants":["Greg Brockman","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"149107","messageId":"1282887373-25618-1-git-send-email-gdb@mit.edu","threadId":"24882","inReplyTo":null,"subject":"[PATCH] shell: Display errors from improperly-formatted command lines","fromName":"Greg Brockman","fromEmail":"gdb@mit.edu","sentAt":"2010-08-27T05:36:13Z","receivedAt":"2010-08-27T05:36:13Z","isPatch":true,"sender":{"key":"gdb@mit.edu","avatar":"https://gravatar.com/avatar/3b907cf60d0cadf6d0659d5429d971b16965fb6b1e3f5acd26a6ba2974b45da4?d=mp&s=160"},"body":"The interface for split_cmdline has changed such that the caller holds\nresponsibility for printing any error messages.  This patch changes\nthe git shell to print these error messages as appropriate.\n---\n shell.c |   16 +++++++++++++---\n 1 files changed, 13 insertions(+), 3 deletions(-)\n\nThe error behavior of split_cmdline was changed in the patch  'split_cmdline: Allow\ncaller to access error string'.  This updates git-shell to deal with printing out\nsplit_cmdline errors itself.\n\ndiff --git a/shell.c b/shell.c\nindex b539cdf..7be826d 100644\n--- a/shell.c\n+++ b/shell.c\n@@ -74,8 +74,10 @@ static void run_shell(void)\n \t\tconst char *prog;\n \t\tchar *full_cmd;\n \t\tchar *rawargs;\n+\t\tchar *split_args;\n \t\tconst char **argv;\n \t\tint code;\n+\t\tint count;\n \n \t\tfprintf(stderr, \"git> \");\n \t\tif (strbuf_getline(&line, stdin, '\\n') == EOF) {\n@@ -85,7 +87,12 @@ static void run_shell(void)\n \t\t}\n \t\tstrbuf_trim(&line);\n \t\trawargs = strbuf_detach(&line, NULL);\n-\t\tif (split_cmdline(rawargs, &argv) == -1) {\n+\t\tsplit_args = xstrdup(rawargs);\n+\t\tcount = split_cmdline(split_args, &argv);\n+\t\tif (count < 0) {\n+\t\t\tfprintf(stderr, \"invalid command format '%s': %s\\n\", rawargs,\n+\t\t\t\tsplit_cmdline_strerror(count));\n+\t\t\tfree(split_args);\n \t\t\tfree(rawargs);\n \t\t\tcontinue;\n \t\t}\n@@ -129,6 +136,7 @@ int main(int argc, char **argv)\n \tconst char **user_argv;\n \tstruct commands *cmd;\n \tint devnull_fd;\n+\tint count;\n \n \tgit_setup_gettext();\n \n@@ -193,7 +201,8 @@ int main(int argc, char **argv)\n \t}\n \n \tcd_to_homedir();\n-\tif (split_cmdline(prog, &user_argv) != -1) {\n+\tcount = split_cmdline(prog, &user_argv);\n+\tif (count >= 0) {\n \t\tif (is_valid_cmd_name(user_argv[0])) {\n \t\t\tprog = make_cmd(user_argv[0]);\n \t\t\tuser_argv[0] = prog;\n@@ -204,6 +213,7 @@ int main(int argc, char **argv)\n \t\tdie(\"unrecognized command '%s'\", argv[2]);\n \t} else {\n \t\tfree(prog);\n-\t\tdie(\"invalid command format '%s'\", argv[2]);\n+\t\tdie(\"invalid command format '%s': %s\", argv[2],\n+\t\t    split_cmdline_strerror(count));\n \t}\n }\n-- \n1.7.0.4\n"},{"id":"149130","messageId":"7vlj7shsn5.fsf@alter.siamese.dyndns.org","threadId":"24882","inReplyTo":"1282887373-25618-1-git-send-email-gdb@mit.edu","subject":"Re: [PATCH] shell: Display errors from improperly-formatted command lines","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-08-27T17:28:30Z","receivedAt":"2010-08-27T17:28:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Greg Brockman <gdb@MIT.EDU> writes:\n\n> The interface for split_cmdline has changed such that the caller holds\n> responsibility for printing any error messages.  This patch changes\n> the git shell to print these error messages as appropriate.\n> ---\n>  shell.c |   16 +++++++++++++---\n>  1 files changed, 13 insertions(+), 3 deletions(-)\n\nForgot to sign-off?\n\n> The error behavior of split_cmdline was changed in the patch  'split_cmdline: Allow\n> caller to access error string'.  This updates git-shell to deal with printing out\n> split_cmdline errors itself.\n\nThanks for being careful.  I'll merge gb/split-cmdline-errmsg topic (which\nalready is in master) to gb/shell-ext topic (which is cooking in next) and\nthen apply this on top.  With this update I suppose the topic is ready to\nbe in the next release?\n"},{"id":"149134","messageId":"AANLkTim9Dbqt2Bs5F-PMYFrAwo4mAL6iVxmvYX1x4UYE@mail.gmail.com","threadId":"24882","inReplyTo":"7vlj7shsn5.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] shell: Display errors from improperly-formatted command lines","fromName":"Greg Brockman","fromEmail":"gdb@mit.edu","sentAt":"2010-08-27T17:32:05Z","receivedAt":"2010-08-27T17:32:05Z","isPatch":true,"sender":{"key":"gdb@mit.edu","avatar":"https://gravatar.com/avatar/3b907cf60d0cadf6d0659d5429d971b16965fb6b1e3f5acd26a6ba2974b45da4?d=mp&s=160"},"body":">>  shell.c |   16 +++++++++++++---\n>>  1 files changed, 13 insertions(+), 3 deletions(-)\n>\n> Forgot to sign-off?\nYes, sorry:\nSigned-off-by: Greg Brockman <gdb@mit.edu>\n\n>> The error behavior of split_cmdline was changed in the patch  'split_cmdline: Allow\n>> caller to access error string'.  This updates git-shell to deal with printing out\n>> split_cmdline errors itself.\n>\n> Thanks for being careful.  I'll merge gb/split-cmdline-errmsg topic (which\n> already is in master) to gb/shell-ext topic (which is cooking in next) and\n> then apply this on top.  With this update I suppose the topic is ready to\n> be in the next release?\nYep, I believe it's ready.\n\nThanks,\n\nGreg\n"}]}