Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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>
  • Loading branch information...
commit ad9ac6db5d58de08d0497b9184e86926377c20dd 1 parent 64fdc08
Greg Brockman authored committed

Showing 4 changed files with 18 additions and 4 deletions. Show diff stats Hide diff stats

  1. +12 2 alias.c
  2. +2 1  builtin/merge.c
  3. +2 0  cache.h
  4. +2 1  git.c
14 alias.c
@@ -22,6 +22,13 @@ char *alias_lookup(const char *alias)
22 22 return alias_val;
23 23 }
24 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 +
25 32 int split_cmdline(char *cmdline, const char ***argv)
26 33 {
27 34 int src, dst, count = 0, size = 16;
@@ -53,7 +60,7 @@ int split_cmdline(char *cmdline, const char ***argv)
53 60 if (!c) {
54 61 free(*argv);
55 62 *argv = NULL;
56   - return error("cmdline ends with \\");
  63 + return -SPLIT_CMDLINE_BAD_ENDING;
57 64 }
58 65 }
59 66 cmdline[dst++] = c;
@@ -66,7 +73,7 @@ int split_cmdline(char *cmdline, const char ***argv)
66 73 if (quoted) {
67 74 free(*argv);
68 75 *argv = NULL;
69   - return error("unclosed quote");
  76 + return -SPLIT_CMDLINE_UNCLOSED_QUOTE;
70 77 }
71 78
72 79 ALLOC_GROW(*argv, count+1, size);
@@ -75,3 +82,6 @@ int split_cmdline(char *cmdline, const char ***argv)
75 82 return count;
76 83 }
77 84
  85 +const char *split_cmdline_strerror(int split_cmdline_errno) {
  86 + return split_cmdline_errors[-split_cmdline_errno-1];
  87 +}
3  builtin/merge.c
@@ -486,7 +486,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
486 486 buf = xstrdup(v);
487 487 argc = split_cmdline(buf, &argv);
488 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));
490 491 argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
491 492 memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
492 493 argc++;
2  cache.h
@@ -1096,6 +1096,8 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix);
1096 1096
1097 1097 char *alias_lookup(const char *alias);
1098 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);
1099 1101
1100 1102 /* builtin/merge.c */
1101 1103 int checkout_fast_forward(const unsigned char *from, const unsigned char *to);
3  git.c
@@ -188,7 +188,8 @@ static int handle_alias(int *argcp, const char ***argv)
188 188 }
189 189 count = split_cmdline(alias_string, &new_argv);
190 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));
192 193 option_count = handle_options(&new_argv, &count, &envchanged);
193 194 if (envchanged)
194 195 die("alias '%s' changes environment variables\n"

0 comments on commit ad9ac6d

Please sign in to comment.
Something went wrong with that request. Please try again.