3 static const char *alias_key
;
4 static char *alias_val
;
6 static int alias_lookup_cb(const char *k
, const char *v
, void *cb
)
9 if (skip_prefix(k
, "alias.", &name
) && !strcmp(name
, alias_key
)) {
11 return config_error_nonbool(k
);
12 alias_val
= xstrdup(v
);
18 char *alias_lookup(const char *alias
)
22 git_config(alias_lookup_cb
, NULL
);
26 #define SPLIT_CMDLINE_BAD_ENDING 1
27 #define SPLIT_CMDLINE_UNCLOSED_QUOTE 2
28 static const char *split_cmdline_errors
[] = {
29 "cmdline ends with \\",
33 int split_cmdline(char *cmdline
, const char ***argv
)
35 int src
, dst
, count
= 0, size
= 16;
38 *argv
= xmalloc(sizeof(**argv
) * size
);
40 /* split alias_string */
41 (*argv
)[count
++] = cmdline
;
42 for (src
= dst
= 0; cmdline
[src
];) {
43 char c
= cmdline
[src
];
44 if (!quoted
&& isspace(c
)) {
47 && isspace(cmdline
[src
]))
49 ALLOC_GROW(*argv
, count
+ 1, size
);
50 (*argv
)[count
++] = cmdline
+ dst
;
51 } else if (!quoted
&& (c
== '\'' || c
== '"')) {
54 } else if (c
== quoted
) {
58 if (c
== '\\' && quoted
!= '\'') {
64 return -SPLIT_CMDLINE_BAD_ENDING
;
77 return -SPLIT_CMDLINE_UNCLOSED_QUOTE
;
80 ALLOC_GROW(*argv
, count
+ 1, size
);
81 (*argv
)[count
] = NULL
;
86 const char *split_cmdline_strerror(int split_cmdline_errno
)
88 return split_cmdline_errors
[-split_cmdline_errno
- 1];