Skip to contentSkip to conversation

shell: Display errors from improperly-formatted command lines

PATCH In review Greg Brockman 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 shell: Display errors from improperly-formatted command lines

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.

shell.c +13 -3
index b539cdf..7be826d 100644
@@ -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));
 	}
 }
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 6 lines · 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(-)

Forgot to sign-off?

Quoted 3 lines

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?

#2 lore raw
Quoted 4 lines
Quoted 2 lines

 shell.c |   16 +++++++++++++---

 1 files changed, 13 insertions(+), 3 deletions(-)

Forgot to sign-off?

Yes, sorry:

Quoted 8 lines
Quoted 3 lines

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