]> git.ipfire.org Git - thirdparty/git.git/commitdiff
object-file: move empty_tree struct into find_cached_object()
authorJeff King <peff@peff.net>
Mon, 18 Nov 2024 09:55:11 +0000 (04:55 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 18 Nov 2024 12:48:47 +0000 (21:48 +0900)
The fake empty_tree struct is a static global, but the only code that
looks at it is find_cached_object(). The struct itself is a little odd,
with an invalid "oid" field that is handled specially by that function.

Since it's really just an implementation detail, let's move it to a
static within the function. That future-proofs against other code trying
to use it and seeing the weird oid value.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-file.c

index 19fc4afa436e0df5701fb398a7eeb5e25eb1aec8..4d4280543e8e3ecddae9f676d85cf1f386a349d3 100644 (file)
@@ -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;