From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, vdye@github.com, me@ttaylorr.com,
Derrick Stolee <derrickstolee@github.com>,
Derrick Stolee <derrickstolee@github.com>
Subject: [PATCH v2 3/3] cache: use const char * for get_object_directory()
Date: Mon, 25 Apr 2022 18:27:14 +0000 [thread overview]
Message-ID: <c9b13f0e1465f8dd41399bba533b3499fc8c8f5d.1650911234.git.gitgitgadget@gmail.com> (raw)
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
prev parent reply other threads:[~2022-04-25 18:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-21 14:57 [PATCH 0/2] multi-pack-index: use real paths for --object-dir Derrick Stolee via GitGitGadget
2022-04-21 14:57 ` [PATCH 1/2] midx: use real paths in lookup_multi_pack_index() Derrick Stolee via GitGitGadget
2022-04-21 14:57 ` [PATCH 2/2] multi-pack-index: use --object-dir real path Derrick Stolee via GitGitGadget
2022-04-21 19:50 ` Victoria Dye
2022-04-21 19:55 ` Derrick Stolee
2022-04-21 20:28 ` Junio C Hamano
2022-04-25 18:27 ` [PATCH v2 0/3] multi-pack-index: use real paths for --object-dir Derrick Stolee via GitGitGadget
2022-04-25 18:27 ` [PATCH v2 1/3] midx: use real paths in lookup_multi_pack_index() Derrick Stolee via GitGitGadget
2022-04-25 18:27 ` [PATCH v2 2/3] multi-pack-index: use --object-dir real path Derrick Stolee via GitGitGadget
2022-04-25 18:58 ` Junio C Hamano
2022-04-25 18:27 ` Derrick Stolee via GitGitGadget [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c9b13f0e1465f8dd41399bba533b3499fc8c8f5d.1650911234.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=me@ttaylorr.com \
--cc=vdye@github.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).