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
)
8 if (starts_with(k
, "alias.") && !strcmp(k
+ 6, alias_key
)) {
10 return config_error_nonbool(k
);
11 alias_val
= xstrdup(v
);
17 char *alias_lookup(const char *alias
)
21 git_config(alias_lookup_cb
, NULL
);
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 \\",
32 int split_cmdline(char *cmdline
, const char ***argv
)
34 int src
, dst
, count
= 0, size
= 16;
37 *argv
= xmalloc(sizeof(**argv
) * size
);
39 /* split alias_string */
40 (*argv
)[count
++] = cmdline
;
41 for (src
= dst
= 0; cmdline
[src
];) {
42 char c
= cmdline
[src
];
43 if (!quoted
&& isspace(c
)) {
46 && isspace(cmdline
[src
]))
48 ALLOC_GROW(*argv
, count
+ 1, size
);
49 (*argv
)[count
++] = cmdline
+ dst
;
50 } else if (!quoted
&& (c
== '\'' || c
== '"')) {
53 } else if (c
== quoted
) {
57 if (c
== '\\' && quoted
!= '\'') {
63 return -SPLIT_CMDLINE_BAD_ENDING
;
76 return -SPLIT_CMDLINE_UNCLOSED_QUOTE
;
79 ALLOC_GROW(*argv
, count
+ 1, size
);
80 (*argv
)[count
] = NULL
;
85 const char *split_cmdline_strerror(int split_cmdline_errno
)
87 return split_cmdline_errors
[-split_cmdline_errno
- 1];