commit - f43793a4e6eda593d67d4872bc7f03398fbd65d9
commit + e83c06347d9516d0180594769020b3013a232414
blob - 694024dff777495df250aba392c630bb04e3e65a
blob + 158483e7592b870d9c2e3ac5e44abea57616549f
--- lib/repository.c
+++ lib/repository.c
{
const struct got_error *err = NULL;
const char *repo_abspath = NULL;
- size_t repolen, cwdlen, len;
- char *cwd, *canonpath, *path = NULL;
+ size_t repolen, len;
+ char *canonpath, *path = NULL;
*in_repo_path = NULL;
-
- cwd = getcwd(NULL, 0);
- if (cwd == NULL)
- return got_error_from_errno("getcwd");
canonpath = strdup(input_path);
if (canonpath == NULL) {
goto done;
}
} else {
- int is_repo_child = 0, is_cwd_child = 0;
+ int is_repo_child = 0;
path = realpath(canonpath, NULL);
if (path == NULL) {
}
repolen = strlen(repo_abspath);
- cwdlen = strlen(cwd);
len = strlen(path);
if (len > repolen && strncmp(path, repo_abspath, repolen) == 0)
is_repo_child = 1;
- if (len > cwdlen && strncmp(path, cwd, cwdlen) == 0)
- is_cwd_child = 1;
if (strcmp(path, repo_abspath) == 0) {
free(path);
err = got_error_from_errno("strdup");
goto done;
}
- } else if (is_repo_child && is_cwd_child) {
- char *child;
- /* Strip common prefix with repository path. */
- err = got_path_skip_common_ancestor(&child,
- repo_abspath, path);
- if (err)
- goto done;
- free(path);
- path = child;
} else if (is_repo_child) {
/* Matched an on-disk path inside repository. */
if (got_repo_is_bare(repo)) {
free(path);
path = child;
}
- } else if (is_cwd_child) {
- char *child;
- /* Strip common prefix with cwd. */
- err = got_path_skip_common_ancestor(&child, cwd,
- path);
- if (err)
- goto done;
- free(path);
- path = child;
} else {
/*
* Matched unrelated on-disk path.
}
done:
- free(cwd);
free(canonpath);
if (err)
free(path);