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