Skip to content
  • Jeff King's avatar
    packfile: fix pack basename computation · fc789156
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    When we have a multi-pack-index that covers many packfiles, we try to
    avoid opening the .idx for those packfiles. To do that we feed the pack
    name to midx_contains_pack(). But that function wants to see only the
    basename, which we compute using strrchr() to find the final slash. But
    that leaves an extra "/" at the start of our string.
    
    We can fix this by incrementing the pointer. That also raises the
    question of what to do when the name does not have a '/' at all. This
    should generally not happen (we always find files in "pack/"), but it
    doesn't hurt to be defensive here.
    
    Let's wrap all of that up in a helper function and make it publicly
    available, since a later patch will need to use it, too.
    
    The tests don't notice because there's nothing about opening those .idx
    files that would cause us to give incorrect output. It's just a little
    slower. The new test checks this case by corrupting the covered .idx,
    and then making sure we don't complain about it.
    
    We also have to tweak t5570, which intentionally corrupts a .idx file
    and expects us to notice it. When run with GIT_TEST_MULTI_PACK_INDEX,
    this will fail since we now will (correctly) not bother opening the .idx
    at all. We can fix that by unconditionally dropping any midx that's
    there, which ensures we'll have to read the .idx.
    
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    fc789156