commit - 9aceaadf35fc979f62e0a6761e967d2089f2103c
commit + aff6eea4a3dab188aabdf9b0c721a5a3cc1dbac7
blob - 50af4bbdfaba1517957e9e217dbfbdb2f9d71b17
blob + 4ed0eaabe20911ce9b81b13c0b1bc933ac507ab4
--- lib/repository.c
+++ lib/repository.c
{
struct got_repository *repo = NULL;
const struct got_error *err = NULL;
- char *abspath;
+ char *abspath, *repo_path = NULL;
int i, tried_root = 0;
*repop = NULL;
if (err)
goto done;
- path = realpath(abspath, NULL);
- if (path == NULL) {
+ repo_path = realpath(abspath, NULL);
+ if (repo_path == NULL) {
err = got_error_from_errno2("realpath", abspath);
goto done;
}
- do {
- err = open_repo(repo, path);
+ for (;;) {
+ char *parent_path;
+
+ err = open_repo(repo, repo_path);
if (err == NULL)
break;
if (err->code != GOT_ERR_NOT_GIT_REPO)
goto done;
- if (path[0] == '/' && path[1] == '\0') {
+ if (repo_path[0] == '/' && repo_path[1] == '\0') {
if (tried_root) {
err = got_error(GOT_ERR_NOT_GIT_REPO);
goto done;
}
tried_root = 1;
}
- path = dirname(path);
- if (path == NULL) {
- err = got_error_from_errno2("dirname", path);
+ err = got_path_dirname(&parent_path, repo_path);
+ if (err)
goto done;
- }
- } while (path);
+ free(repo_path);
+ repo_path = parent_path;
+ }
err = read_gotconfig(repo);
if (err)
else
*repop = repo;
free(abspath);
+ free(repo_path);
return err;
}