make got_repo_get_path() return const char *
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
diff --git a/got/got.c b/got/got.c
index 40d1c25..bb5861b 100644
--- a/got/got.c
+++ b/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;
}
diff --git a/include/got_repository.h b/include/got_repository.h
index 37f50bb..2c7f872 100644
--- a/include/got_repository.h
+++ b/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 *);
diff --git a/lib/repository.c b/lib/repository.c
index 941438e..bd30c00 100644
--- a/lib/repository.c
+++ b/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_repository *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_repository *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_repository *repo,
}
done:
- free(repo_abspath);
free(cwd);
free(canonpath);
if (err)
diff --git a/lib/worktree.c b/lib/worktree.c
index 79520bd..6e5fc2e 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -187,7 +187,6 @@ got_worktree_init(const char *path, struct got_reference *head_ref,
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_reference *head_ref,
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;