do not require that got applications normalize paths
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
diff --git a/lib/path.c b/lib/path.c
index 5adeb94..021ae95 100644
--- a/lib/path.c
+++ b/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;
-}
diff --git a/lib/repository.c b/lib/repository.c
index f96d838..afc8ee3 100644
--- a/lib/repository.c
+++ b/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 (!is_git_repo(repo))
- return got_error(GOT_ERR_NOT_GIT_REPO);
+ if (repo->path == NULL) {
+ err = got_error(GOT_ERR_BAD_PATH);
+ goto done;
+ }
+
+ 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
diff --git a/regress/repository/repository_test.c b/regress/repository/repository_test.c
index 4ddf99c..f70ab8c 100644
--- a/regress/repository/repository_test.c
+++ b/regress/repository/repository_test.c
@@ -19,7 +19,6 @@
#include <sha1.h>
#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);