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