| 247 | } |
| 248 | |
| 249 | static void list_commands_in_dir(struct cmdnames *cmds, |
| 250 | const char *path, |
| 251 | const char *prefix) |
| 252 | { |
| 253 | DIR *dir = opendir(path); |
| 254 | struct dirent *de; |
| 255 | struct strbuf buf = STRBUF_INIT; |
| 256 | int len; |
| 257 | |
| 258 | if (!dir) |
| 259 | return; |
| 260 | if (!prefix) |
| 261 | prefix = "git-"; |
| 262 | |
| 263 | strbuf_addf(&buf, "%s/", path); |
| 264 | len = buf.len; |
| 265 | |
| 266 | while ((de = readdir(dir)) != NULL) { |
| 267 | const char *ent; |
| 268 | size_t entlen; |
| 269 | |
| 270 | if (!skip_prefix(de->d_name, prefix, &ent)) |
| 271 | continue; |
| 272 | |
| 273 | strbuf_setlen(&buf, len); |
| 274 | strbuf_addstr(&buf, de->d_name); |
| 275 | if (!is_executable(buf.buf)) |
| 276 | continue; |
| 277 | |
| 278 | entlen = strlen(ent); |
| 279 | strip_suffix(ent, ".exe", &entlen); |
| 280 | |
| 281 | add_cmdname(cmds, ent, entlen); |
| 282 | } |
| 283 | closedir(dir); |
| 284 | strbuf_release(&buf); |
| 285 | } |
| 286 | |
| 287 | void load_command_list(const char *prefix, |
| 288 | struct cmdnames *main_cmds, |
no test coverage detected