Skip to content

Commit 1f08e5c

Browse files
raalkmlgitster
authored andcommitted
Allow git help work without PATH set
Just because we can Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c7371e9 commit 1f08e5c

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

help.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -178,37 +178,34 @@ void load_command_list(const char *prefix,
178178
struct cmdnames *other_cmds)
179179
{
180180
const char *env_path = getenv("PATH");
181-
char *paths, *path, *colon;
182181
const char *exec_path = git_exec_path();
183182

184-
if (exec_path)
183+
if (exec_path) {
185184
list_commands_in_dir(main_cmds, exec_path, prefix);
186-
187-
if (!env_path) {
188-
fprintf(stderr, "PATH not set\n");
189-
exit(1);
185+
qsort(main_cmds->names, main_cmds->cnt,
186+
sizeof(*main_cmds->names), cmdname_compare);
187+
uniq(main_cmds);
190188
}
191189

192-
path = paths = xstrdup(env_path);
193-
while (1) {
194-
if ((colon = strchr(path, PATH_SEP)))
195-
*colon = 0;
196-
197-
list_commands_in_dir(other_cmds, path, prefix);
190+
if (env_path) {
191+
char *paths, *path, *colon;
192+
path = paths = xstrdup(env_path);
193+
while (1) {
194+
if ((colon = strchr(path, PATH_SEP)))
195+
*colon = 0;
198196

199-
if (!colon)
200-
break;
201-
path = colon + 1;
202-
}
203-
free(paths);
197+
list_commands_in_dir(other_cmds, path, prefix);
204198

205-
qsort(main_cmds->names, main_cmds->cnt,
206-
sizeof(*main_cmds->names), cmdname_compare);
207-
uniq(main_cmds);
199+
if (!colon)
200+
break;
201+
path = colon + 1;
202+
}
203+
free(paths);
208204

209-
qsort(other_cmds->names, other_cmds->cnt,
210-
sizeof(*other_cmds->names), cmdname_compare);
211-
uniq(other_cmds);
205+
qsort(other_cmds->names, other_cmds->cnt,
206+
sizeof(*other_cmds->names), cmdname_compare);
207+
uniq(other_cmds);
208+
}
212209
exclude_cmds(other_cmds, main_cmds);
213210
}
214211

0 commit comments

Comments
 (0)