Re: [PATCH 05/27] object-store: move packed_git and packed_git_mru to object store
- From
Stefan Beller <sbeller@google.com>
- Date
- Feb 23, 2018, 20:01 UTC
- Message-ID
- <CAGZ79kZjOz0RcBHZDrT3g3Rjkx=Q94aj81Y+PGmjcB11oAn16w@mail.gmail.com>
- In-Reply-To
- <xmqqy3jmxb8s.fsf@gitster-ct.c.googlers.com>
On Wed, Feb 21, 2018 at 1:51 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 41 quoted lines
> Stefan Beller <sbeller@google.com> writes:
>
>> +
>> +/*
>> + * The mru list_head is supposed to be initialized using
>> + * the LIST_HEAD macro, assigning prev/next to itself.
>> + * However this doesn't work in this case as some compilers dislike
>> + * that macro on member variables. Use NULL instead as that is defined
>> + * and accepted, deferring the real init to prepare_packed_git_mru(). */
>> +#define __MRU_INIT { NULL, NULL }
>> +#define RAW_OBJECT_STORE_INIT { NULL, NULL, __MRU_INIT, NULL, NULL }
>
> I do not think it has to be this way to abuse two NULLs, if you
> faithfully mimicked how LIST_HEAD() macro is constructed. The
> reason why it does not try to introduce
>
> struct list_head x = LIST_HEAD_INIT;
>
> and instead, uses
>
> LIST_HEAD(x);
>
> is because of the need for self referral. If we learn from it, we
> can do the same, i.e. instead of doing
>
> struct raw_object_store x = RAW_OBJECT_STORE_INIT;
>
> we can do
>
> RAW_OBJECT_STORE(x);
>
> that expands to
>
> struct raw_object_store x = {
> ...
> { &x.packed_git_mru, &x.packed_git_mru },
> ...
> };
>
> no? Then we do not need such a lengthy comment that reads only like
> an excuse ;-)We cannot do this, because the object store is directly embedded into the the_repository (not as a pointer), which is a global on its own. So we'd have to do this at the repository level, which I would not want. I'd want to have the #defines where the structs are declared.
Any guidance on how to do that correctly with self referential definitions without making the object store a pointer then?