All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] shell: Display errors from improperly-formatted command lines
@ 2010-08-27  5:36 Greg Brockman
  2010-08-27 17:28 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Brockman @ 2010-08-27  5:36 UTC (permalink / raw)
  To: git, gitster; +Cc: Greg Brockman

The interface for split_cmdline has changed such that the caller holds
responsibility for printing any error messages.  This patch changes
the git shell to print these error messages as appropriate.
---
 shell.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

The error behavior of split_cmdline was changed in the patch  'split_cmdline: Allow
caller to access error string'.  This updates git-shell to deal with printing out
split_cmdline errors itself.

diff --git a/shell.c b/shell.c
index b539cdf..7be826d 100644
--- a/shell.c
+++ b/shell.c
@@ -74,8 +74,10 @@ static void run_shell(void)
 		const char *prog;
 		char *full_cmd;
 		char *rawargs;
+		char *split_args;
 		const char **argv;
 		int code;
+		int count;
 
 		fprintf(stderr, "git> ");
 		if (strbuf_getline(&line, stdin, '\n') == EOF) {
@@ -85,7 +87,12 @@ static void run_shell(void)
 		}
 		strbuf_trim(&line);
 		rawargs = strbuf_detach(&line, NULL);
-		if (split_cmdline(rawargs, &argv) == -1) {
+		split_args = xstrdup(rawargs);
+		count = split_cmdline(split_args, &argv);
+		if (count < 0) {
+			fprintf(stderr, "invalid command format '%s': %s\n", rawargs,
+				split_cmdline_strerror(count));
+			free(split_args);
 			free(rawargs);
 			continue;
 		}
@@ -129,6 +136,7 @@ int main(int argc, char **argv)
 	const char **user_argv;
 	struct commands *cmd;
 	int devnull_fd;
+	int count;
 
 	git_setup_gettext();
 
@@ -193,7 +201,8 @@ int main(int argc, char **argv)
 	}
 
 	cd_to_homedir();
-	if (split_cmdline(prog, &user_argv) != -1) {
+	count = split_cmdline(prog, &user_argv);
+	if (count >= 0) {
 		if (is_valid_cmd_name(user_argv[0])) {
 			prog = make_cmd(user_argv[0]);
 			user_argv[0] = prog;
@@ -204,6 +213,7 @@ int main(int argc, char **argv)
 		die("unrecognized command '%s'", argv[2]);
 	} else {
 		free(prog);
-		die("invalid command format '%s'", argv[2]);
+		die("invalid command format '%s': %s", argv[2],
+		    split_cmdline_strerror(count));
 	}
 }
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] shell: Display errors from improperly-formatted command lines
  2010-08-27  5:36 [PATCH] shell: Display errors from improperly-formatted command lines Greg Brockman
@ 2010-08-27 17:28 ` Junio C Hamano
  2010-08-27 17:32   ` Greg Brockman
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2010-08-27 17:28 UTC (permalink / raw)
  To: Greg Brockman; +Cc: git

Greg Brockman <gdb@MIT.EDU> writes:

> The interface for split_cmdline has changed such that the caller holds
> responsibility for printing any error messages.  This patch changes
> the git shell to print these error messages as appropriate.
> ---
>  shell.c |   16 +++++++++++++---
>  1 files changed, 13 insertions(+), 3 deletions(-)

Forgot to sign-off?

> The error behavior of split_cmdline was changed in the patch  'split_cmdline: Allow
> caller to access error string'.  This updates git-shell to deal with printing out
> split_cmdline errors itself.

Thanks for being careful.  I'll merge gb/split-cmdline-errmsg topic (which
already is in master) to gb/shell-ext topic (which is cooking in next) and
then apply this on top.  With this update I suppose the topic is ready to
be in the next release?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] shell: Display errors from improperly-formatted command lines
  2010-08-27 17:28 ` Junio C Hamano
@ 2010-08-27 17:32   ` Greg Brockman
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Brockman @ 2010-08-27 17:32 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

>>  shell.c |   16 +++++++++++++---
>>  1 files changed, 13 insertions(+), 3 deletions(-)
>
> Forgot to sign-off?
Yes, sorry:
Signed-off-by: Greg Brockman <gdb@mit.edu>

>> The error behavior of split_cmdline was changed in the patch  'split_cmdline: Allow
>> caller to access error string'.  This updates git-shell to deal with printing out
>> split_cmdline errors itself.
>
> Thanks for being careful.  I'll merge gb/split-cmdline-errmsg topic (which
> already is in master) to gb/shell-ext topic (which is cooking in next) and
> then apply this on top.  With this update I suppose the topic is ready to
> be in the next release?
Yep, I believe it's ready.

Thanks,

Greg

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-08-27 17:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-27  5:36 [PATCH] shell: Display errors from improperly-formatted command lines Greg Brockman
2010-08-27 17:28 ` Junio C Hamano
2010-08-27 17:32   ` Greg Brockman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.