5 struct config_alias_data {
10 static int config_alias_cb(const char *key, const char *value, void *d)
12 struct config_alias_data *data = d;
15 if (skip_prefix(key, "alias.", &p) && !strcasecmp(p, data->alias))
16 return git_config_string((const char **)&data->v, key, value);
21 char *alias_lookup(const char *alias)
23 struct config_alias_data data = { alias, NULL };
25 read_early_config(config_alias_cb, &data);
30 #define SPLIT_CMDLINE_BAD_ENDING 1
31 #define SPLIT_CMDLINE_UNCLOSED_QUOTE 2
32 static const char *split_cmdline_errors[] = {
33 "cmdline ends with \\",
37 int split_cmdline(char *cmdline, const char ***argv)
39 int src, dst, count = 0, size = 16;
42 ALLOC_ARRAY(*argv, size);
44 /* split alias_string */
45 (*argv)[count++] = cmdline;
46 for (src = dst = 0; cmdline[src];) {
47 char c = cmdline[src];
48 if (!quoted && isspace(c)) {
51 && isspace(cmdline[src]))
53 ALLOC_GROW(*argv, count + 1, size);
54 (*argv)[count++] = cmdline + dst;
55 } else if (!quoted && (c == '\'' || c == '"')) {
58 } else if (c == quoted) {
62 if (c == '\\' && quoted != '\'') {
67 return -SPLIT_CMDLINE_BAD_ENDING;
79 return -SPLIT_CMDLINE_UNCLOSED_QUOTE;
82 ALLOC_GROW(*argv, count + 1, size);
83 (*argv)[count] = NULL;
88 const char *split_cmdline_strerror(int split_cmdline_errno)
90 return split_cmdline_errors[-split_cmdline_errno - 1];