Commit 6e9da951ccdba2e3e9ffe11c8a0ae030930fcd11

Stefan Sperling 2019-01-06T10:46:46

make got_repo_get_path_git_dir() return const char *

diff --git a/include/got_repository.h b/include/got_repository.h
index 2c7f872..4f82cdf 100644
--- a/include/got_repository.h
+++ b/include/got_repository.h
@@ -21,12 +21,12 @@ 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 *);
+const char *got_repo_get_path_git_dir(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_git_dir(struct got_repository *);
 char *got_repo_get_path_objects(struct got_repository *);
 char *got_repo_get_path_objects_pack(struct got_repository *);
 char *got_repo_get_path_refs(struct got_repository *);
diff --git a/lib/reference.c b/lib/reference.c
index a2c1904..caef761 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -153,7 +153,7 @@ get_refs_dir_path(struct got_repository *repo, const char *refname)
 	    strcmp(refname, GOT_REF_MERGE_HEAD) == 0 ||
 	    strcmp(refname, GOT_REF_FETCH_HEAD) == 0 ||
 	    strncmp(refname, "refs/", 5) == 0)
-		return got_repo_get_path_git_dir(repo);
+		return strdup(got_repo_get_path_git_dir(repo));
 
 	return got_repo_get_path_refs(repo);
 }
diff --git a/lib/repository.c b/lib/repository.c
index bd30c00..938d64f 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -72,10 +72,10 @@ got_repo_get_path(struct got_repository *repo)
 	return repo->path;
 }
 
-char *
+const char *
 got_repo_get_path_git_dir(struct got_repository *repo)
 {
-	return strdup(repo->path_git_dir);
+	return repo->path_git_dir;
 }
 
 int
@@ -123,7 +123,7 @@ get_path_head(struct got_repository *repo)
 static int
 is_git_repo(struct got_repository *repo)
 {
-	char *path_git = got_repo_get_path_git_dir(repo);
+	const char *path_git = got_repo_get_path_git_dir(repo);
 	char *path_objects = got_repo_get_path_objects(repo);
 	char *path_refs = got_repo_get_path_refs(repo);
 	char *path_head = get_path_head(repo);
@@ -158,7 +158,6 @@ is_git_repo(struct got_repository *repo)
 
 	ret = 1;
 done:
-	free(path_git);
 	free(path_objects);
 	free(path_refs);
 	free(path_head);