From: Greg Brockman <gdb@MIT.EDU>
To: git@vger.kernel.org, gitster@pobox.com
Cc: Greg Brockman <gdb@mit.edu>
Subject: [PATCH] shell: Display errors from improperly-formatted command lines
Date: Fri, 27 Aug 2010 01:36:13 -0400 [thread overview]
Message-ID: <1282887373-25618-1-git-send-email-gdb@mit.edu> (raw)
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
next reply other threads:[~2010-08-27 5:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-27 5:36 Greg Brockman [this message]
2010-08-27 17:28 ` [PATCH] shell: Display errors from improperly-formatted command lines Junio C Hamano
2010-08-27 17:32 ` Greg Brockman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1282887373-25618-1-git-send-email-gdb@mit.edu \
--to=gdb@mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).