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. Signed-off-by: Greg Brockman <gdb@mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Greg Brockman committed
Aug 27, 2010 at 01:36 UTC
9f29fe9a779e55e7387577cd7f712de0b13b5cd6
1 file changed
+13
-3
shell.c
+13
-3
@@ -73,8 +73,10 @@ static void run_shell(void)
73
const char *prog;
74
char *full_cmd;
75
char *rawargs;
76
+ char *split_args;
77
const char **argv;
78
int code;
79
+ int count;
80
81
fprintf(stderr, "git> ");
82
if (strbuf_getline(&line, stdin, '\n') == EOF) {
@@ -84,7 +86,12 @@ static void run_shell(void)
86
}
87
strbuf_trim(&line);
88
rawargs = strbuf_detach(&line, NULL);
87
- if (split_cmdline(rawargs, &argv) == -1) {
89
+ split_args = xstrdup(rawargs);
90
+ count = split_cmdline(split_args, &argv);
91
+ if (count < 0) {
92
+ fprintf(stderr, "invalid command format '%s': %s\n", rawargs,
93
+ split_cmdline_strerror(count));
94
+ free(split_args);
95
free(rawargs);
96
continue;
97
}
@@ -128,6 +135,7 @@ int main(int argc, char **argv)
135
const char **user_argv;
136
struct commands *cmd;
137
int devnull_fd;
138
+ int count;
139
140
/*
141
* Always open file descriptors 0/1/2 to avoid clobbering files
@@ -190,7 +198,8 @@ int main(int argc, char **argv)
198
}
199
200
cd_to_homedir();
193
- if (split_cmdline(prog, &user_argv) != -1) {
201
+ count = split_cmdline(prog, &user_argv);
202
+ if (count >= 0) {
203
if (is_valid_cmd_name(user_argv[0])) {
204
prog = make_cmd(user_argv[0]);
205
user_argv[0] = prog;
@@ -201,6 +210,7 @@ int main(int argc, char **argv)
210
die("unrecognized command '%s'", argv[2]);
211
} else {
212
free(prog);
204
- die("invalid command format '%s'", argv[2]);
213
+ die("invalid command format '%s': %s", argv[2],
214
+ split_cmdline_strerror(count));
215
}
216
}