]> git.ipfire.org Git - thirdparty/git.git/commitdiff
cache: use const char * for get_object_directory()
authorDerrick Stolee <derrickstolee@github.com>
Mon, 25 Apr 2022 18:27:14 +0000 (18:27 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 Apr 2022 18:31:13 +0000 (11:31 -0700)
The get_object_directory() method returns the exact string stored at
the_repository->objects->odb->path. The return type of "char *" implies
that the caller must keep track of the buffer and free() it when
complete. This causes significant problems later when the ODB is
accessed.

Use "const char *" as the return type to avoid this confusion. There are
no current callers that care about the non-const definition.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
environment.c

diff --git a/cache.h b/cache.h
index 281f00ab1b161dc71d0bcdae91222e9429ba0342..d8b0dc2ff1f5537ba57704b90e5625882968bc8b 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -567,7 +567,7 @@ extern char *git_work_tree_cfg;
 int is_inside_work_tree(void);
 const char *get_git_dir(void);
 const char *get_git_common_dir(void);
-char *get_object_directory(void);
+const char *get_object_directory(void);
 char *get_index_file(void);
 char *get_graft_file(struct repository *r);
 void set_git_dir(const char *path, int make_realpath);
index fd0501e77a5b8d96dad8b5fe3714b74f13786be7..4e49ee0d60e0514a4bcb7aa12e97568e88bf079e 100644 (file)
@@ -271,7 +271,7 @@ const char *get_git_work_tree(void)
        return the_repository->worktree;
 }
 
-char *get_object_directory(void)
+const char *get_object_directory(void)
 {
        if (!the_repository->objects->odb)
                BUG("git environment hasn't been setup");