t / t5319-multi-pack-index.shon commit multi-pack-index: read packfile list (396f257)
   1#!/bin/sh
   2
   3test_description='multi-pack-indexes'
   4. ./test-lib.sh
   5
   6midx_read_expect () {
   7        NUM_PACKS=$1
   8        cat >expect <<-EOF
   9        header: 4d494458 1 0 $NUM_PACKS
  10        object-dir: .
  11        EOF
  12        test-tool read-midx . >actual &&
  13        test_cmp expect actual
  14}
  15
  16test_expect_success 'write midx with no packs' '
  17        test_when_finished rm -f pack/multi-pack-index &&
  18        git multi-pack-index --object-dir=. write &&
  19        midx_read_expect 0
  20'
  21
  22generate_objects () {
  23        i=$1
  24        iii=$(printf '%03i' $i)
  25        {
  26                test-tool genrandom "bar" 200 &&
  27                test-tool genrandom "baz $iii" 50
  28        } >wide_delta_$iii &&
  29        {
  30                test-tool genrandom "foo"$i 100 &&
  31                test-tool genrandom "foo"$(( $i + 1 )) 100 &&
  32                test-tool genrandom "foo"$(( $i + 2 )) 100
  33        } >deep_delta_$iii &&
  34        {
  35                echo $iii &&
  36                test-tool genrandom "$iii" 8192
  37        } >file_$iii &&
  38        git update-index --add file_$iii deep_delta_$iii wide_delta_$iii
  39}
  40
  41commit_and_list_objects () {
  42        {
  43                echo 101 &&
  44                test-tool genrandom 100 8192;
  45        } >file_101 &&
  46        git update-index --add file_101 &&
  47        tree=$(git write-tree) &&
  48        commit=$(git commit-tree $tree -p HEAD</dev/null) &&
  49        {
  50                echo $tree &&
  51                git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\)        .*/\\1/"
  52        } >obj-list &&
  53        git reset --hard $commit
  54}
  55
  56test_expect_success 'create objects' '
  57        test_commit initial &&
  58        for i in $(test_seq 1 5)
  59        do
  60                generate_objects $i
  61        done &&
  62        commit_and_list_objects
  63'
  64
  65test_expect_success 'write midx with one v1 pack' '
  66        pack=$(git pack-objects --index-version=1 pack/test <obj-list) &&
  67        test_when_finished rm pack/test-$pack.pack pack/test-$pack.idx pack/multi-pack-index &&
  68        git multi-pack-index --object-dir=. write &&
  69        midx_read_expect 1
  70'
  71
  72test_expect_success 'write midx with one v2 pack' '
  73        git pack-objects --index-version=2,0x40 pack/test <obj-list &&
  74        git multi-pack-index --object-dir=. write &&
  75        midx_read_expect 1
  76'
  77
  78test_expect_success 'add more objects' '
  79        for i in $(test_seq 6 10)
  80        do
  81                generate_objects $i
  82        done &&
  83        commit_and_list_objects
  84'
  85
  86test_expect_success 'write midx with two packs' '
  87        git pack-objects --index-version=1 pack/test-2 <obj-list &&
  88        git multi-pack-index --object-dir=. write &&
  89        midx_read_expect 2
  90'
  91
  92test_expect_success 'add more packs' '
  93        for j in $(test_seq 11 20)
  94        do
  95                generate_objects $j &&
  96                commit_and_list_objects &&
  97                git pack-objects --index-version=2 pack/test-pack <obj-list
  98        done
  99'
 100
 101test_expect_success 'write midx with twelve packs' '
 102        git multi-pack-index --object-dir=. write &&
 103        midx_read_expect 12
 104'
 105
 106test_done