summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 64fdc08)
raw | patch | inline | side by side (parent: 64fdc08)
author | Greg Brockman <gdb@MIT.EDU> | |
Sat, 7 Aug 2010 05:13:39 +0000 (01:13 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 11 Aug 2010 16:36:23 +0000 (09:36 -0700) |
This allows the caller to add its own error message to that returned
by split_cmdline. Thus error output following a failed split_cmdline
can be of the form
fatal: Bad alias.test string: cmdline ends with \
rather than
error: cmdline ends with \
fatal: Bad alias.test string
Signed-off-by: Greg Brockman <gdb@mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
by split_cmdline. Thus error output following a failed split_cmdline
can be of the form
fatal: Bad alias.test string: cmdline ends with \
rather than
error: cmdline ends with \
fatal: Bad alias.test string
Signed-off-by: Greg Brockman <gdb@mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
alias.c | patch | blob | history | |
builtin/merge.c | patch | blob | history | |
cache.h | patch | blob | history | |
git.c | patch | blob | history |
index 372b7d809301f9e3e936459e405cd6f2627bd4a9..eb9f08b912b2089d434926fc6083ac5ab90c73bc 100644 (file)
--- a/alias.c
+++ b/alias.c
return alias_val;
}
+#define SPLIT_CMDLINE_BAD_ENDING 1
+#define SPLIT_CMDLINE_UNCLOSED_QUOTE 2
+static const char *split_cmdline_errors[] = {
+ "cmdline ends with \\",
+ "unclosed quote"
+};
+
int split_cmdline(char *cmdline, const char ***argv)
{
int src, dst, count = 0, size = 16;
if (!c) {
free(*argv);
*argv = NULL;
- return error("cmdline ends with \\");
+ return -SPLIT_CMDLINE_BAD_ENDING;
}
}
cmdline[dst++] = c;
if (quoted) {
free(*argv);
*argv = NULL;
- return error("unclosed quote");
+ return -SPLIT_CMDLINE_UNCLOSED_QUOTE;
}
ALLOC_GROW(*argv, count+1, size);
return count;
}
+const char *split_cmdline_strerror(int split_cmdline_errno) {
+ return split_cmdline_errors[-split_cmdline_errno-1];
+}
diff --git a/builtin/merge.c b/builtin/merge.c
index 37ce4f589f6582abf0d1ef5bd263f590a16853d5..b48826372f94e8dc48a37c3ff5ea4c727788f92e 100644 (file)
--- a/builtin/merge.c
+++ b/builtin/merge.c
buf = xstrdup(v);
argc = split_cmdline(buf, &argv);
if (argc < 0)
- die("Bad branch.%s.mergeoptions string", branch);
+ die("Bad branch.%s.mergeoptions string: %s", branch,
+ split_cmdline_strerror(argc));
argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
argc++;
index c9fa3df7f5b343ecea980ceb423e7c23d2eb22b2..7466ad04fac5efdfb179177f55e6be3f5cacb466 100644 (file)
--- a/cache.h
+++ b/cache.h
char *alias_lookup(const char *alias);
int split_cmdline(char *cmdline, const char ***argv);
+/* Takes a negative value returned by split_cmdline */
+const char *split_cmdline_strerror(int cmdline_errno);
/* builtin/merge.c */
int checkout_fast_forward(const unsigned char *from, const unsigned char *to);
index 17538117a5ccfd48129a873697d8674e86f512f5..da56f31a673121f2d45806dd089e633d0aa6a462 100644 (file)
--- a/git.c
+++ b/git.c
}
count = split_cmdline(alias_string, &new_argv);
if (count < 0)
- die("Bad alias.%s string", alias_command);
+ die("Bad alias.%s string: %s", alias_command,
+ split_cmdline_strerror(count));
option_count = handle_options(&new_argv, &count, &envchanged);
if (envchanged)
die("alias '%s' changes environment variables\n"