git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 3/3] cache: use const char * for get_object_directory()

From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Date
Apr 25, 2022, 18:27 UTC
Message-ID
<c9b13f0e1465f8dd41399bba533b3499fc8c8f5d.1650911234.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1221.v2.git.1650911234.gitgitgadget@gmail.com>
From: Derrick Stolee <derrickstolee@github.com>

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>
---
 cache.h       | 2 +-
 environment.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/cache.h b/cache.h
index 6226f6a8a53..595582becc8 100644
--- a/cache.h
+++ b/cache.h
@@ -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);
diff --git a/environment.c b/environment.c
index 5bff1b386fd..b3296ce7d15 100644
--- a/environment.c
+++ b/environment.c
@@ -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");
-- 
gitgitgadget
Previous: Junio C Hamano
Message 11 of 11 in “multi-pack-index: use real paths for --object-dir”
  1. 0/2 multi-pack-index: use real paths for --object-dirDerrick Stolee via GitGitGadget, Apr 21, 2022
  2. 1/2 midx: use real paths in lookup_multi_pack_index()Derrick Stolee via GitGitGadget, Apr 21, 2022
  3. 2/2 multi-pack-index: use --object-dir real pathDerrick Stolee via GitGitGadget, Apr 21, 2022
  4. Victoria DyeApr 21, 2022
  5. Derrick StoleeApr 21, 2022
  6. Junio C HamanoApr 21, 2022
  7. 0/3 multi-pack-index: use real paths for --object-dirDerrick Stolee via GitGitGadget, Apr 25, 2022
  8. 1/3 midx: use real paths in lookup_multi_pack_index()Derrick Stolee via GitGitGadget, Apr 25, 2022
  9. 2/3 multi-pack-index: use --object-dir real pathDerrick Stolee via GitGitGadget, Apr 25, 2022
  10. Junio C HamanoApr 25, 2022
  11. 3/3 cache: use const char * for get_object_directory()Derrick Stolee via GitGitGadget, Apr 25, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.