1 #include "git-compat-util.h"
6 #include "string-list.h"
8 struct config_alias_data
{
11 struct string_list
*list
;
14 static int config_alias_cb(const char *key
, const char *value
, void *d
)
16 struct config_alias_data
*data
= d
;
19 if (!skip_prefix(key
, "alias.", &p
))
23 if (!strcasecmp(p
, data
->alias
))
24 return git_config_string((const char **)&data
->v
,
26 } else if (data
->list
) {
27 string_list_append(data
->list
, p
);
33 char *alias_lookup(const char *alias
)
35 struct config_alias_data data
= { alias
, NULL
};
37 read_early_config(config_alias_cb
, &data
);
42 void list_aliases(struct string_list
*list
)
44 struct config_alias_data data
= { NULL
, NULL
, list
};
46 read_early_config(config_alias_cb
, &data
);
49 #define SPLIT_CMDLINE_BAD_ENDING 1
50 #define SPLIT_CMDLINE_UNCLOSED_QUOTE 2
51 #define SPLIT_CMDLINE_ARGC_OVERFLOW 3
52 static const char *split_cmdline_errors
[] = {
53 N_("cmdline ends with \\"),
55 N_("too many arguments"),
58 int split_cmdline(char *cmdline
, const char ***argv
)
60 size_t src
, dst
, count
= 0, size
= 16;
63 ALLOC_ARRAY(*argv
, size
);
65 /* split alias_string */
66 (*argv
)[count
++] = cmdline
;
67 for (src
= dst
= 0; cmdline
[src
];) {
68 char c
= cmdline
[src
];
69 if (!quoted
&& isspace(c
)) {
72 && isspace(cmdline
[src
]))
74 ALLOC_GROW(*argv
, count
+ 1, size
);
75 (*argv
)[count
++] = cmdline
+ dst
;
76 } else if (!quoted
&& (c
== '\'' || c
== '"')) {
79 } else if (c
== quoted
) {
83 if (c
== '\\' && quoted
!= '\'') {
88 return -SPLIT_CMDLINE_BAD_ENDING
;
100 return -SPLIT_CMDLINE_UNCLOSED_QUOTE
;
103 if (count
>= INT_MAX
) {
104 FREE_AND_NULL(*argv
);
105 return -SPLIT_CMDLINE_ARGC_OVERFLOW
;
108 ALLOC_GROW(*argv
, count
+ 1, size
);
109 (*argv
)[count
] = NULL
;
114 const char *split_cmdline_strerror(int split_cmdline_errno
)
116 return split_cmdline_errors
[-split_cmdline_errno
- 1];