From: Patrick Steinhardt <ps@pks.im>
To: Jeff King <peff@peff.net>
Cc: Sam James <sam@gentoo.org>,
"brian m. carlson" <sandals@crustytoothpaste.net>,
git@vger.kernel.org
Subject: Re: [PATCH 3/5] object-file: move empty_tree struct into find_cached_object()
Date: Mon, 18 Nov 2024 08:40:34 +0100 [thread overview]
Message-ID: <ZzrvciXuOfw_V6ox@pks.im> (raw)
In-Reply-To: <20241117090842.GC3409496@coredump.intra.peff.net>
On Sun, Nov 17, 2024 at 04:08:42AM -0500, Jeff King wrote:
> diff --git a/object-file.c b/object-file.c
> index b7c4fdcabd..5fadd470c1 100644
> --- a/object-file.c
> +++ b/object-file.c
> @@ -325,14 +325,13 @@ static struct cached_object {
> } *cached_objects;
> static int cached_object_nr, cached_object_alloc;
>
> -static struct cached_object empty_tree = {
> - /* no oid needed; we'll look it up manually based on the_hash_algo */
> - .type = OBJ_TREE,
> - .buf = "",
> -};
> -
> static struct cached_object *find_cached_object(const struct object_id *oid)
> {
> + static struct cached_object empty_tree = {
> + /* no oid needed; we'll look it up manually based on the_hash_algo */
> + .type = OBJ_TREE,
> + .buf = "",
> + };
> int i;
> struct cached_object *co = cached_objects;
I was wondering whether we want to also mark this as `const` so that no
caller ever gets the idea of modifying the struct. Something like the
below patch (which applies on "master", so it of course would have to
adapt to your changes).
Patrick
diff --git a/object-file.c b/object-file.c
index b1a3463852..f15a3f6a5f 100644
--- a/object-file.c
+++ b/object-file.c
@@ -321,7 +321,7 @@ static struct cached_object {
} *cached_objects;
static int cached_object_nr, cached_object_alloc;
-static struct cached_object empty_tree = {
+static const struct cached_object empty_tree = {
.oid = {
.hash = EMPTY_TREE_SHA1_BIN_LITERAL,
},
@@ -329,7 +329,7 @@ static struct cached_object empty_tree = {
.buf = "",
};
-static struct cached_object *find_cached_object(const struct object_id *oid)
+static const struct cached_object *find_cached_object(const struct object_id *oid)
{
int i;
struct cached_object *co = cached_objects;
@@ -1627,7 +1627,7 @@ static int do_oid_object_info_extended(struct repository *r,
struct object_info *oi, unsigned flags)
{
static struct object_info blank_oi = OBJECT_INFO_INIT;
- struct cached_object *co;
+ const struct cached_object *co;
struct pack_entry e;
int rtype;
const struct object_id *real = oid;
next prev parent reply other threads:[~2024-11-18 7:40 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-17 2:50 -Wunterminated-string-initialization warning with GCC 15 in object-file.c Sam James
2024-11-17 9:03 ` Jeff King
2024-11-17 9:08 ` [PATCH 1/5] object-file: prefer array-of-bytes initializer for hash literals Jeff King
2024-11-17 9:52 ` René Scharfe
2024-11-18 9:06 ` Jeff King
2024-11-17 9:08 ` [PATCH 2/5] object-file: drop confusing oid initializer of empty_tree struct Jeff King
2024-11-17 9:08 ` [PATCH 3/5] object-file: move empty_tree struct into find_cached_object() Jeff King
2024-11-18 7:40 ` Patrick Steinhardt [this message]
2024-11-18 9:17 ` Jeff King
2024-11-17 9:10 ` [PATCH 4/5] object-file: drop oid field from find_cached_object() return value Jeff King
2024-11-17 9:14 ` [PATCH 5/5] object-file: inline empty tree and blob literals Jeff King
2024-11-18 7:40 ` Patrick Steinhardt
2024-11-17 16:03 ` -Wunterminated-string-initialization warning with GCC 15 in object-file.c brian m. carlson
2024-11-18 9:19 ` Jeff King
2024-11-18 9:58 ` Sam James
2024-11-18 7:40 ` Patrick Steinhardt
2024-11-18 9:54 ` [PATCH 0/6] -Wunterminated-string-initialization warning + cleanups Jeff King
2024-11-18 9:54 ` [PATCH 1/6] object-file: prefer array-of-bytes initializer for hash literals Jeff King
2024-11-18 9:55 ` [PATCH 2/6] object-file: drop confusing oid initializer of empty_tree struct Jeff King
2024-11-18 9:55 ` [PATCH 3/6] object-file: move empty_tree struct into find_cached_object() Jeff King
2024-11-18 9:55 ` [PATCH 4/6] object-file: drop oid field from find_cached_object() return value Jeff King
2024-11-18 9:55 ` [PATCH 5/6] object-file: treat cached_object values as const Jeff King
2024-11-18 9:55 ` [PATCH 6/6] object-file: inline empty tree and blob literals Jeff King
2024-11-18 10:51 ` [PATCH 0/6] -Wunterminated-string-initialization warning + cleanups Patrick Steinhardt
2024-11-18 12:49 ` Junio C Hamano
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=ZzrvciXuOfw_V6ox@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=sam@gentoo.org \
--cc=sandals@crustytoothpaste.net \
/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