real_path_if_valid(): remove unsafe API

This commit continues the work started with previous commit.

Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Alexandr Miloslavskiy
2020-03-10 13:11:23 +00:00
committed by Junio C Hamano
parent 3d7747e318
commit 4530a85b4c
6 changed files with 14 additions and 26 deletions

View File

@ -226,17 +226,20 @@ struct worktree *find_worktree(struct worktree **list,
struct worktree *find_worktree_by_path(struct worktree **list, const char *p)
{
struct strbuf wt_path = STRBUF_INIT;
char *path = real_pathdup(p, 0);
if (!path)
return NULL;
for (; *list; list++) {
const char *wt_path = real_path_if_valid((*list)->path);
if (!strbuf_realpath(&wt_path, (*list)->path, 0))
continue;
if (wt_path && !fspathcmp(path, wt_path))
if (!fspathcmp(path, wt_path.buf))
break;
}
free(path);
strbuf_release(&wt_path);
return *list;
}