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