4 struct config_alias_data {
9 static int config_alias_cb(const char *key, const char *value, void *d)
11 struct config_alias_data *data = d;
14 if (skip_prefix(key, "alias.", &p) && !strcasecmp(p, data->alias))
15 return git_config_string((const char **)&data->v, key, value);
20 char *alias_lookup(const char *alias)
22 struct config_alias_data data = { alias, NULL };
24 read_early_config(config_alias_cb, &data);
29 #define SPLIT_CMDLINE_BAD_ENDING 1
30 #define SPLIT_CMDLINE_UNCLOSED_QUOTE 2
31 static const char *split_cmdline_errors[] = {
32 "cmdline ends with \\",
36 int split_cmdline(char *cmdline, const char ***argv)
38 int src, dst, count = 0, size = 16;
41 ALLOC_ARRAY(*argv, size);
43 /* split alias_string */
44 (*argv)[count++] = cmdline;
45 for (src = dst = 0; cmdline[src];) {
46 char c = cmdline[src];
47 if (!quoted && isspace(c)) {
50 && isspace(cmdline[src]))
52 ALLOC_GROW(*argv, count + 1, size);
53 (*argv)[count++] = cmdline + dst;
54 } else if (!quoted && (c == '\'' || c == '"')) {
57 } else if (c == quoted) {
61 if (c == '\\' && quoted != '\'') {
66 return -SPLIT_CMDLINE_BAD_ENDING;
78 return -SPLIT_CMDLINE_UNCLOSED_QUOTE;
81 ALLOC_GROW(*argv, count + 1, size);
82 (*argv)[count] = NULL;
87 const char *split_cmdline_strerror(int split_cmdline_errno)
89 return split_cmdline_errors[-split_cmdline_errno - 1];