Commit Diff


commit - 3e9926ea004f2a839c0600f2daef1d04fca7894d
commit + 7839bc15b2c146222489bd8d61a1dede43fecbbf
blob - 40d1c255b2f0d4d970b035519e51d69d91523940
blob + bb5861b87334a06680c1f45a5291002db4e8204f
--- got/got.c
+++ got/got.c
@@ -422,7 +422,6 @@ cmd_update(int argc, char *argv[])
 	struct got_repository *repo = NULL;
 	struct got_worktree *worktree = NULL;
 	char *worktree_path = NULL;
-	char *repo_path = NULL;
 	struct got_object_id *commit_id = NULL;
 	char *commit_id_str = NULL;
 	int ch;
@@ -471,13 +470,7 @@ cmd_update(int argc, char *argv[])
 	if (error != NULL)
 		goto done;
 
-	repo_path = got_repo_get_path(repo);
-	if (repo_path == NULL) {
-		error = got_error_from_errno();
-		goto done;
-	}
-
-	error = apply_unveil(repo_path, worktree_path);
+	error = apply_unveil(got_repo_get_path(repo), worktree_path);
 	if (error)
 		goto done;
 
@@ -521,7 +514,6 @@ done:
 	free(worktree_path);
 	free(commit_id);
 	free(commit_id_str);
-	free(repo_path);
 	return error;
 }
 
blob - 37f50bb121ab922394e63c883653fa25db30d824
blob + 2c7f872154b99b9eada5a12383625b9d054640b6
--- include/got_repository.h
+++ include/got_repository.h
@@ -20,11 +20,12 @@ struct got_repository;
 const struct got_error *got_repo_open(struct got_repository**, const char *);
 const struct got_error *got_repo_close(struct got_repository*);
 
+const char *got_repo_get_path(struct got_repository *);
+
 /*
  * Obtain paths to various directories within a repository.
  * The caller must dispose of a path with free(3).
  */
-char *got_repo_get_path(struct got_repository *);
 char *got_repo_get_path_git_dir(struct got_repository *);
 char *got_repo_get_path_objects(struct got_repository *);
 char *got_repo_get_path_objects_pack(struct got_repository *);
blob - 941438ef7171b50941a6d4601ad0c38546dfebed
blob + bd30c00e28ab48d392f7c6a02f4f70e2cf90e5e3
--- lib/repository.c
+++ lib/repository.c
@@ -66,10 +66,10 @@
 #define GOT_ORIG_HEAD_FILE	"ORIG_HEAD"
 #define GOT_OBJECTS_PACK_DIR	"objects/pack"
 
-char *
+const char *
 got_repo_get_path(struct got_repository *repo)
 {
-	return strdup(repo->path);
+	return repo->path;
 }
 
 char *
@@ -462,10 +462,10 @@ got_repo_map_path(char **in_repo_path, struct got_repo
     const char *input_path, int check_disk)
 {
 	const struct got_error *err = NULL;
-	char *repo_abspath = NULL, *cwd = NULL;
+	const char *repo_abspath = NULL;
 	struct stat sb;
 	size_t repolen, cwdlen, len;
-	char *canonpath, *path = NULL;
+	char *cwd, *canonpath, *path = NULL;
 
 	*in_repo_path = NULL;
 
@@ -483,10 +483,6 @@ got_repo_map_path(char **in_repo_path, struct got_repo
 		goto done;
 
 	repo_abspath = got_repo_get_path(repo);
-	if (repo_abspath == NULL) {
-		err = got_error_from_errno();
-		goto done;
-	}
 
 	/* TODO: Call "get in-repository path of work-tree node" API. */
 
@@ -584,7 +580,6 @@ got_repo_map_path(char **in_repo_path, struct got_repo
 	}
 
 done:
-	free(repo_abspath);
 	free(cwd);
 	free(canonpath);
 	if (err)
blob - 79520bd02c0689c8b16ebcc2c3a0193916f8bd27
blob + 6e5fc2e147fc218200cc9d247d6cb75a9009faec
--- lib/worktree.c
+++ lib/worktree.c
@@ -187,7 +187,6 @@ got_worktree_init(const char *path, struct got_referen
 	int obj_type;
 	char *path_got = NULL;
 	char *refstr = NULL;
-	char *repo_path = NULL;
 	char *formatstr = NULL;
 	char *absprefix = NULL;
 	char *basestr = NULL;
@@ -251,12 +250,8 @@ got_worktree_init(const char *path, struct got_referen
 		goto done;
 
 	/* Store path to repository. */
-	repo_path = got_repo_get_path(repo);
-	if (repo_path == NULL) {
-		err = got_error_from_errno();
-		goto done;
-	}
-	err = create_meta_file(path_got, GOT_WORKTREE_REPOSITORY, repo_path);
+	err = create_meta_file(path_got, GOT_WORKTREE_REPOSITORY,
+	    got_repo_get_path(repo));
 	if (err)
 		goto done;
 
@@ -280,7 +275,6 @@ done:
 	free(path_got);
 	free(formatstr);
 	free(refstr);
-	free(repo_path);
 	free(absprefix);
 	free(basestr);
 	return err;