Message ID | 20220330073230.61358-1-dyroneteng@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Teng Long | expand |
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().
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); strbuf_release(&buf); return -1; @@ -398,9 +406,17 @@ static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git return -1; } - if (bitmap_git->pack) { + if (bitmap_git->pack || bitmap_git->midx) { /* ignore extra bitmap file; we can only handle one */ - warning("ignoring extra bitmap file: %s", packfile->pack_name); + 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)) : + "", + packfile->pack_name); close(fd); return -1; } diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh index f775fc1ce6..a962f6861f 100755 --- a/t/t5310-pack-bitmaps.sh +++ b/t/t5310-pack-bitmaps.sh @@ -421,6 +421,7 @@ test_expect_success 'complains about multiple pack bitmaps' ' test_line_count = 2 bitmaps && git rev-list --use-bitmap-index HEAD 2>err && + grep "A non-MIDX bitmap has been opened" err && grep "ignoring extra bitmap file" err )