Skip to content

Commit

Permalink
cache: use const char * for get_object_directory()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
derrickstolee committed Apr 25, 2022
1 parent 9d81001 commit af83a7e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,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);
Expand Down
2 changes: 1 addition & 1 deletion environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,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");
Expand Down

0 comments on commit af83a7e

Please sign in to comment.