3 struct config_alias_data {
8 static int config_alias_cb(const char *key, const char *value, void *d)
10 struct config_alias_data *data = d;
13 if (skip_prefix(key, "alias.", &p) && !strcmp(p, data->alias))
14 return git_config_string((const char **)&data->v, key, value);
19 char *alias_lookup(const char *alias)
21 struct config_alias_data data = { alias, NULL };
23 read_early_config(config_alias_cb, &data);
28 #define SPLIT_CMDLINE_BAD_ENDING 1
29 #define SPLIT_CMDLINE_UNCLOSED_QUOTE 2
30 static const char *split_cmdline_errors[] = {
31 "cmdline ends with \\",
35 int split_cmdline(char *cmdline, const char ***argv)
37 int src, dst, count = 0, size = 16;
40 ALLOC_ARRAY(*argv, size);
42 /* split alias_string */
43 (*argv)[count++] = cmdline;
44 for (src = dst = 0; cmdline[src];) {
45 char c = cmdline[src];
46 if (!quoted && isspace(c)) {
49 && isspace(cmdline[src]))
51 ALLOC_GROW(*argv, count + 1, size);
52 (*argv)[count++] = cmdline + dst;
53 } else if (!quoted && (c == '\'' || c == '"')) {
56 } else if (c == quoted) {
60 if (c == '\\' && quoted != '\'') {
66 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];