Subject: Re: Teng Long

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Wed, 30 Mar 2022 15:17:44 +0200

On Wed, Mar 30 2022, Teng Long wrote:

> On Tue, 29 Mar 2022 22:55:39 -0400, Taylor Blau wrote:
>
>> You're right; open_pack_bitmap_1() doesn't need to care about whether or
>> not bitmap_git->midx is or isn't non-NULL, since:
>> 
>>   - if we did open a MIDX bitmap (which we will always attempt first
>>     before trying to open single-pack bitmaps), then we won't even
>>     bother to call open_pack_bitmap() at all.
>> 
>>   - if we _do_ end up within open_pack_bitmap_1(), then we _know_ that
>>     no MIDX bitmap could be found/opened, so there is no need to check
>>     in that case, either.
>> 
>> So I think we realistically could do something like:
>> 
>> --- 8< ---
>> 
>> diff --git a/pack-bitmap.c b/pack-bitmap.c
>> index 97909d48da..6e7c89826d 100644
>> --- a/pack-bitmap.c
>> +++ b/pack-bitmap.c
>> @@ -387,3 +387,3 @@ static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git
>> 
>> -  if (bitmap_git->pack || bitmap_git->midx) {
>> +  if (bitmap_git->pack) {
>>       /* ignore extra bitmap file; we can only handle one */
>> 
>> --- >8 ---
>> ...but having the conditional there from the pre-image doesn't hurt,
>> either, and it makes the error clearer in case of an accidental
>> regression where we start looking for single-pack bitmaps after
>> successfully opening a multi-pack one.
>
> I agree with the "accidental regression", it's a protection without
> any disadvantages so far. So, if we don't remove the "bitmap_git->midx"
> condition for some robust reason, then I think maybe we can let the
> warning more detailed if the "accident" happens, like:
>
> diff --git a/pack-bitmap.c b/pack-bitmap.c
> index 91a6be358d..e64a85bc59 100644
> --- a/pack-bitmap.c
> +++ b/pack-bitmap.c
> @@ -333,7 +333,15 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
>                 struct strbuf buf = STRBUF_INIT;
>                 get_midx_filename(&buf, midx->object_dir);
>                 /* ignore extra bitmap file; we can only handle one */
> -               warning("ignoring extra bitmap file: %s", buf.buf);
> +               warning("%signoring extra bitmap file: %s",
> +                       bitmap_git->pack ?
> +                               xstrfmt("A non-MIDX bitmap has been opened: %s, ",
> +                                       bitmap_git->pack->pack_name) :
> +                       bitmap_git->midx ?
> +                               xstrfmt("A MIDX bitmap has been opened : %s, ",
> +                                       midx_bitmap_filename(bitmap_git->midx)) :
> +                                     "",
> +                       buf.buf);
>                 close(fd);

Aside from any bitmap-specific issues, let's not compose messages like
that via concat, it makes them harder to translate.

In this case the original message doesn't have _(), but looking at the
context that seems to be a simple omission.

It's more verbose, but it's better to split this out into 3x warning()
calls.

It also has the advantage of not leaking memory from the xstrfmt().