Re: [PATCH v1 2/3] pack-bitmap.c: add "break" statement in "open_pack_bitmap()"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 29, 2022 at 10:49:49AM +0800, Teng Long wrote:
> Yeah, the condition and "warning" make it clear to me which is if
> already exists a bitmap of the pack or MIDX is ready, we will give
> warnings and just let it fail (return -1 means a return of NULL in
> "prepare_bitmap_git()", and will then die() in usage cases I found).
>
> In addition of above, I had a question that why we need
> "bitmap_git->midx" in the condition? Because here in
> "open_pack_bitmap_1()" we intent to open the non-midx-bitmap and it's
> after we deal with "open_midx_bitmap()" in "open_bitmap()":

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.

> static int open_bitmap(struct repository *r,
>               struct bitmap_index *bitmap_git)
> {
> 	assert(!bitmap_git->map);
>
> 	if (!open_midx_bitmap(r, bitmap_git))
> 	   return 0;
> 	   return open_pack_bitmap(r, bitmap_git);
> }
>
> So if I understood correct, maybe we can made condition of "bitmap_git->midx" a little
> earlier so that we can avoid to open every packfile,  maybe it's like:
>
> diff --git a/pack-bitmap.c b/pack-bitmap.c
> index 9c666cdb8b..38f53b8f1c 100644
> --- a/pack-bitmap.c
> +++ b/pack-bitmap.c
> @@ -483,11 +483,12 @@ static int open_pack_bitmap(struct repository *r,
>
>         assert(!bitmap_git->map);
>
> -       for (p = get_all_packs(r); p; p = p->next) {
> -               if (open_pack_bitmap_1(bitmap_git, p) == 0)
> -                       ret = 0;
> +       if (!bitmap_git->midx) {
> +               for (p = get_all_packs(r); p; p = p->next) {
> +                       if (open_pack_bitmap_1(bitmap_git, p) == 0)
> +                               ret = 0;
> +               }
>         }
> -
>         return ret;
>  }

This shouldn't be necessary, since we don't bother calling
open_pack_bitmap() at all if open_midx_bitmap() returns success. In
other words, based on the way that open_bitmap() (which is the caller
for both of these functions) is written, we know that once we're in
open_pack_bitmap(), that `bitmap_git->midx` is definitely NULL, which
makes this change a noop.

Thanks,
Taylor



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux