@matheusbsbs / matheus-bagliano / commits / ad9ac6db5d
Fork 0

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>

Greg Brockman committed Aug 7, 2010 at 01:13 UTC ad9ac6db5d58de08d0497b9184e86926377c20dd
4 files changed +18 -4
alias.c
+12 -2
@@ -22,6 +22,13 @@ char *alias_lookup(const char *alias)
22 return alias_val;
23 }
24
25 +#define SPLIT_CMDLINE_BAD_ENDING 1
26 +#define SPLIT_CMDLINE_UNCLOSED_QUOTE 2
27 +static const char *split_cmdline_errors[] = {
28 + "cmdline ends with \\",
29 + "unclosed quote"
30 +};
31 +
32 int split_cmdline(char *cmdline, const char ***argv)
33 {
34 int src, dst, count = 0, size = 16;
@@ -53,7 +60,7 @@ int split_cmdline(char *cmdline, const char ***argv)
60 if (!c) {
61 free(*argv);
62 *argv = NULL;
56 - return error("cmdline ends with \\");
63 + return -SPLIT_CMDLINE_BAD_ENDING;
64 }
65 }
66 cmdline[dst++] = c;
@@ -66,7 +73,7 @@ int split_cmdline(char *cmdline, const char ***argv)
73 if (quoted) {
74 free(*argv);
75 *argv = NULL;
69 - return error("unclosed quote");
76 + return -SPLIT_CMDLINE_UNCLOSED_QUOTE;
77 }
78
79 ALLOC_GROW(*argv, count+1, size);
@@ -75,3 +82,6 @@ int split_cmdline(char *cmdline, const char ***argv)
82 return count;
83 }
84
85 +const char *split_cmdline_strerror(int split_cmdline_errno) {
86 + return split_cmdline_errors[-split_cmdline_errno-1];
87 +}
builtin/merge.c
+2 -1
@@ -486,7 +486,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
486 buf = xstrdup(v);
487 argc = split_cmdline(buf, &argv);
488 if (argc < 0)
489 - die("Bad branch.%s.mergeoptions string", branch);
489 + die("Bad branch.%s.mergeoptions string: %s", branch,
490 + split_cmdline_strerror(argc));
491 argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
492 memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
493 argc++;
cache.h
+2
@@ -1096,6 +1096,8 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix);
1096
1097 char *alias_lookup(const char *alias);
1098 int split_cmdline(char *cmdline, const char ***argv);
1099 +/* Takes a negative value returned by split_cmdline */
1100 +const char *split_cmdline_strerror(int cmdline_errno);
1101
1102 /* builtin/merge.c */
1103 int checkout_fast_forward(const unsigned char *from, const unsigned char *to);
git.c
+2 -1
@@ -188,7 +188,8 @@ static int handle_alias(int *argcp, const char ***argv)
188 }
189 count = split_cmdline(alias_string, &new_argv);
190 if (count < 0)
191 - die("Bad alias.%s string", alias_command);
191 + die("Bad alias.%s string: %s", alias_command,
192 + split_cmdline_strerror(count));
193 option_count = handle_options(&new_argv, &count, &envchanged);
194 if (envchanged)
195 die("alias '%s' changes environment variables\n"