commit 92af54690507460b948ced62a12b3bc7e4b2a244 from: Stefan Sperling date: Sun Nov 05 13:15:47 2017 UTC do not require that got applications normalize paths commit - 4df642d96698f559d3c086843ecd7c411f9963aa commit + 92af54690507460b948ced62a12b3bc7e4b2a244 blob - 5adeb94e5b3caec17009e5f1a22d520949aca1c0 blob + 021ae95760630951fea30363f50a41c41923eb7a --- lib/path.c +++ lib/path.c @@ -60,16 +60,3 @@ got_path_normalize(const char *path) return resolved; } - -int -got_path_is_normalized(const char *path) -{ - char *normpath; - int ret; - - normpath = got_path_normalize(path); - ret = (strcmp(normpath, path) == 0); - free(normpath); - - return ret; -} blob - f96d8386ea1f6ce81118440eab08d45a8edae8dd blob + afc8ee3bb78487c9cbb26074bb67c7d30b5a2694 --- lib/repository.c +++ lib/repository.c @@ -98,26 +98,38 @@ is_git_repo(struct got_repository *repo) } const struct got_error * -got_repo_open(struct got_repository **ret, const char *abspath) +got_repo_open(struct got_repository **ret, const char *path) { - struct got_repository *repo; + struct got_repository *repo = NULL; + const struct got_error *err = NULL; + char *abspath = got_path_get_absolute(path); - if (!got_path_is_absolute(abspath)) - return got_error(GOT_ERR_NOT_ABSPATH); + if (abspath == NULL) + return got_error(GOT_ERR_BAD_PATH); repo = calloc(1, sizeof(*repo)); - if (repo == NULL) - return got_error(GOT_ERR_NO_MEM); + if (repo == NULL) { + err = got_error(GOT_ERR_NO_MEM); + goto done; + } repo->path = got_path_normalize(abspath); - if (repo->path == NULL) - return got_error(GOT_ERR_BAD_PATH); + if (repo->path == NULL) { + err = got_error(GOT_ERR_BAD_PATH); + goto done; + } - if (!is_git_repo(repo)) - return got_error(GOT_ERR_NOT_GIT_REPO); + if (!is_git_repo(repo)) { + err = got_error(GOT_ERR_NOT_GIT_REPO); + goto done; + } *ret = repo; - return NULL; +done: + if (err) + free(repo); + free(abspath); + return err; } void blob - 4ddf99cac3ba850c83d0b0537e4d63326194cf65 blob + f70ab8cdc937290abf9b2d0afd92733f30acc517 --- regress/repository/repository_test.c +++ regress/repository/repository_test.c @@ -19,7 +19,6 @@ #include #include "got_error.h" -#include "got_path.h" #include "got_refs.h" #include "got_repository.h" @@ -36,8 +35,7 @@ repo_open_test(const char *repo_path) const char *abspath; int ret; - abspath = got_path_normalize(repo_path); - err = got_repo_open(&repo, abspath); + err = got_repo_open(&repo, repo_path); ret = (err == NULL && repo != NULL); got_repo_close(repo); return ret; @@ -49,11 +47,9 @@ repo_get_head_ref(const char *repo_path) const struct got_error *err; struct got_repository *repo; struct got_reference *head_ref; - const char *abspath; int ret; - abspath = got_path_normalize(repo_path); - err = got_repo_open(&repo, abspath); + err = got_repo_open(&repo, repo_path); if (err != NULL || repo == NULL) return 0; err = got_repo_get_reference(&head_ref, repo, GOT_REF_HEAD);