summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b6f637d)
raw | patch | inline | side by side (parent: b6f637d)
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | |
Sun, 27 Jul 2008 20:34:14 +0000 (22:34 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 27 Jul 2008 21:14:38 +0000 (14:14 -0700) |
The function list_commands_in_dir() tried to be lazy and just chdir()
to the directory which entries it listed, so that the check if the
file is executable could be done on dir->d_name.
However, there is no good reason to jump around wildly just to find
all Git commands.
Instead, have a strbuf and construct the full path dynamically.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
to the directory which entries it listed, so that the check if the
file is executable could be done on dir->d_name.
However, there is no good reason to jump around wildly just to find
all Git commands.
Instead, have a strbuf and construct the full path dynamically.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
help.c | patch | blob | history |
index bfc84aed10d49b1eb641d920a102e94d2e905fda..3cb19628965685ce59a5377b81bef975851996e8 100644 (file)
--- a/help.c
+++ b/help.c
int prefix_len = strlen(prefix);
DIR *dir = opendir(path);
struct dirent *de;
+ struct strbuf buf = STRBUF_INIT;
+ int len;
- if (!dir || chdir(path))
+ if (!dir)
return 0;
+ strbuf_addf(&buf, "%s/", path);
+ len = buf.len;
+
while ((de = readdir(dir)) != NULL) {
int entlen;
if (prefixcmp(de->d_name, prefix))
continue;
- if (!is_executable(de->d_name))
+ strbuf_setlen(&buf, len);
+ strbuf_addstr(&buf, de->d_name);
+ if (!is_executable(buf.buf))
continue;
entlen = strlen(de->d_name) - prefix_len;
add_cmdname(cmds, de->d_name + prefix_len, entlen);
}
closedir(dir);
+ strbuf_release(&buf);
return longest;
}