multi-pack-index: verify packname order
authorDerrick Stolee <dstolee@microsoft.com>
Thu, 13 Sep 2018 18:02:18 +0000 (11:02 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Sep 2018 20:49:41 +0000 (13:49 -0700)
The final check we make while loading a multi-pack-index is that
the packfile names are in lexicographical order. Make this error
be a die() instead.

In order to test this condition, we need multiple packfiles.
Earlier in t5319-multi-pack-index.sh, we tested the interaction with
'git repack' but this limits us to one packfile in our object dir.
Move these repack tests until after the 'verify' tests.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
midx.c
t/t5319-multi-pack-index.sh
diff --git a/midx.c b/midx.c
index 9e43216d09441d15c982270bbc080881543d5c18..939e8fa391ca9bea8264643fc8c02fca5723e26d 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -157,12 +157,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
 
                cur_pack_name += strlen(cur_pack_name) + 1;
 
-               if (i && strcmp(m->pack_names[i], m->pack_names[i - 1]) <= 0) {
-                       error(_("multi-pack-index pack names out of order: '%s' before '%s'"),
+               if (i && strcmp(m->pack_names[i], m->pack_names[i - 1]) <= 0)
+                       die(_("multi-pack-index pack names out of order: '%s' before '%s'"),
                              m->pack_names[i - 1],
                              m->pack_names[i]);
-                       goto cleanup_fail;
-               }
        }
 
        return m;
index c54b6e71882a8d5cc54d983158fdcfb0c62db929..01a3cd6b004d7c57e9367107c156e9771fb074d8 100755 (executable)
@@ -181,6 +181,11 @@ MIDX_BYTE_CHUNK_COUNT=6
 MIDX_HEADER_SIZE=12
 MIDX_BYTE_CHUNK_ID=$MIDX_HEADER_SIZE
 MIDX_BYTE_CHUNK_OFFSET=$(($MIDX_HEADER_SIZE + 4))
+MIDX_NUM_CHUNKS=5
+MIDX_CHUNK_LOOKUP_WIDTH=12
+MIDX_OFFSET_PACKNAMES=$(($MIDX_HEADER_SIZE + \
+                        $MIDX_NUM_CHUNKS * $MIDX_CHUNK_LOOKUP_WIDTH))
+MIDX_BYTE_PACKNAME_ORDER=$(($MIDX_OFFSET_PACKNAMES + 2))
 
 test_expect_success 'verify bad version' '
        corrupt_midx_and_verify $MIDX_BYTE_VERSION "\00" $objdir \
@@ -212,6 +217,11 @@ test_expect_success 'verify invalid chunk offset' '
                "invalid chunk offset (too large)"
 '
 
+test_expect_success 'verify packnames out of order' '
+       corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "z" $objdir \
+               "pack names out of order"
+'
+
 test_expect_success 'repack removes multi-pack-index' '
        test_path_is_file $objdir/pack/multi-pack-index &&
        git repack -adf &&