summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Brockman <gdb@MIT.EDU>2010-08-07 01:13:39 -0400
committerJunio C Hamano <gitster@pobox.com>2010-08-11 09:36:23 -0700
commitad9ac6db5d58de08d0497b9184e86926377c20dd (patch)
tree02a6ec6fd2fd40799d9d1c4c1fcba657b5adbcc4
parent64fdc08dac6694d1e754580e7acb82dfa4988bb9 (diff)
downloadgit-ad9ac6db5d58de08d0497b9184e86926377c20dd.tar.gz
split_cmdline: Allow caller to access error string
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>
-rw-r--r--alias.c14
-rw-r--r--builtin/merge.c3
-rw-r--r--cache.h2
-rw-r--r--git.c3
4 files changed, 18 insertions, 4 deletions
diff --git a/alias.c b/alias.c
index 372b7d8093..eb9f08b912 100644
--- a/alias.c
+++ b/alias.c
@@ -22,6 +22,13 @@ char *alias_lookup(const char *alias)
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;
@@ -53,7 +60,7 @@ int split_cmdline(char *cmdline, const char ***argv)
if (!c) {
free(*argv);
*argv = NULL;
- return error("cmdline ends with \\");
+ return -SPLIT_CMDLINE_BAD_ENDING;
}
}
cmdline[dst++] = c;
@@ -66,7 +73,7 @@ int split_cmdline(char *cmdline, const char ***argv)
if (quoted) {
free(*argv);
*argv = NULL;
- return error("unclosed quote");
+ return -SPLIT_CMDLINE_UNCLOSED_QUOTE;
}
ALLOC_GROW(*argv, count+1, size);
@@ -75,3 +82,6 @@ int split_cmdline(char *cmdline, const char ***argv)
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 37ce4f589f..b48826372f 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -486,7 +486,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
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++;
diff --git a/cache.h b/cache.h
index c9fa3df7f5..7466ad04fa 100644
--- a/cache.h
+++ b/cache.h
@@ -1096,6 +1096,8 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix);
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);
diff --git a/git.c b/git.c
index 17538117a5..da56f31a67 100644
--- a/git.c
+++ b/git.c
@@ -188,7 +188,8 @@ static int handle_alias(int *argcp, const char ***argv)
}
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"