Commit 92af54690507460b948ced62a12b3bc7e4b2a244

Stefan Sperling 2017-11-05T14:15:47

do not require that got applications normalize paths

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);