(command.CommandList
  children: [
    (command.ShAssignment
      pairs: [
        (assign_pair
          lhs: (sh_lhs_expr.Name name:test_description)
          op: assign_op.Equal
          rhs: {(SQ <'pack index with 64-bit offsets and object CRC'>)}
          spids: [13]
        )
      ]
    )
    (C {<.>} {<'./test-lib.sh'>})
    (C {<test_expect_success>} {(SQ <setup>)} 
      {
        (SQ <'rm -rf .git &&\n'> <'     git init &&\n'> <'     git config pack.threads 1 &&\n'> 
          <'     i=1 &&\n'> <'     while test $i -le 100\n'> <'     do\n'> <'         iii=$(printf '>
        ) <Id.Lit_Other '%'> <03i> 
        (SQ <' $i)\n'> <'         test-genrandom "bar" 200 > wide_delta_$iii &&\n'> 
          <'         test-genrandom "baz $iii" 50 >> wide_delta_$iii &&\n'> <'         test-genrandom "foo"$i 100 > deep_delta_$iii &&\n'> 
          <'         test-genrandom "foo"$(expr $i + 1) 100 >> deep_delta_$iii &&\n'> <'         test-genrandom "foo"$(expr $i + 2) 100 >> deep_delta_$iii &&\n'> 
          <'         echo $iii >file_$iii &&\n'> <'         test-genrandom "$iii" 8192 >>file_$iii &&\n'> 
          <'         git update-index --add file_$iii deep_delta_$iii wide_delta_$iii &&\n'> <'         i=$(expr $i + 1) || return 1\n'> <'     done &&\n'> 
          <'     { echo 101 && test-genrandom 100 8192; } >file_101 &&\n'> <'     git update-index --add file_101 &&\n'> <'     tree=$(git write-tree) &&\n'> 
          <'     commit=$(git commit-tree $tree </dev/null) && {\n'> <'\t echo $tree &&\n'> <'\t git ls-tree $tree | sed -e "s/.* \\\\([0-9a-f]*\\\\)\t.*/\\\\1/"\n'> 
          <'     } >obj-list &&\n'> <'     git update-ref HEAD $commit'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'pack-objects with index version 1'>)} 
      {
        (SQ <'pack1=$(git pack-objects --index-version=1 test-1 <obj-list) &&\n'> 
          <'     git verify-pack -v "test-1-${pack1}.pack"'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'pack-objects with index version 2'>)} 
      {
        (SQ <'pack2=$(git pack-objects --index-version=2 test-2 <obj-list) &&\n'> 
          <'     git verify-pack -v "test-2-${pack2}.pack"'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'both packs should be identical'>)} 
      {(SQ <'cmp "test-1-${pack1}.pack" "test-2-${pack2}.pack"'>)}
    )
    (C {<test_expect_success>} {(SQ <'index v1 and index v2 should be different'>)} 
      {(SQ <'! cmp "test-1-${pack1}.idx" "test-2-${pack2}.idx"'>)}
    )
    (C {<test_expect_success>} {(SQ <'index-pack with index version 1'>)} 
      {(SQ <'git index-pack --index-version=1 -o 1.idx "test-1-${pack1}.pack"'>)}
    )
    (C {<test_expect_success>} {(SQ <'index-pack with index version 2'>)} 
      {(SQ <'git index-pack --index-version=2 -o 2.idx "test-1-${pack1}.pack"'>)}
    )
    (C {<test_expect_success>} {(SQ <'index-pack results should match pack-objects ones'>)} 
      {(SQ <'cmp "test-1-${pack1}.idx" "1.idx" &&\n'> <'     cmp "test-2-${pack2}.idx" "2.idx"'>)}
    )
    (C {<test_expect_success>} {(SQ <'index-pack --verify on index version 1'>)} 
      {(SQ <'\n'> <'\tgit index-pack --verify "test-1-${pack1}.pack"\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'index-pack --verify on index version 2'>)} 
      {(SQ <'\n'> <'\tgit index-pack --verify "test-2-${pack2}.pack"\n'>)}
    )
    (C {<test_expect_success>} {(SQ <'pack-objects --index-version=2, is not accepted'>)} 
      {(SQ <'test_must_fail git pack-objects --index-version=2, test-3 <obj-list'>)}
    )
    (C {<test_expect_success>} {(SQ <'index v2: force some 64-bit offsets with pack-objects'>)} 
      {(SQ <'pack3=$(git pack-objects --index-version=2,0x40000 test-3 <obj-list)'>)}
    )
    (command.If
      arms: [
        (if_arm
          cond: [
            (command.AndOr
              ops: [Id.Op_DPipe]
              children: [
                (command.ShAssignment
                  pairs: [
                    (assign_pair
                      lhs: (sh_lhs_expr.Name name:msg)
                      op: assign_op.Equal
                      rhs: 
                        {
                          (command_sub
                            left_token: <Id.Left_DollarParen '$('>
                            child: 
                              (command.Simple
                                words: [
                                  {<git>}
                                  {<verify-pack>}
                                  {<-v>}
                                  {(DQ <test-3-> (${ Id.VSub_Name pack3) <.pack>)}
                                ]
                                redirects: [
                                  (redir
                                    op: <Id.Redir_GreatAnd '2>&'>
                                    loc: (redir_loc.Fd fd:2)
                                    arg: {<1>}
                                  )
                                ]
                                do_fork: T
                              )
                          )
                        }
                      spids: [231]
                    )
                  ]
                )
                (command.Pipeline
                  children: [
                    (command.Subshell
                      child: 
                        (command.Pipeline
                          children: [
                            (C {<echo>} {(DQ ($ Id.VSub_DollarName '$msg'))})
                            (C {<grep>} {(DQ <'pack too large .* off_t'>)})
                          ]
                          negated: F
                        )
                    )
                  ]
                  negated: T
                )
              ]
            )
          ]
          action: [(C {<test_set_prereq>} {<OFF64_T>})]
          spids: [229 272]
        )
      ]
      else_action: [(C {<say>} {(DQ <'# skipping tests concerning 64-bit offsets'>)})]
    )
    (C {<test_expect_success>} {<OFF64_T>} {(SQ <'index v2: verify a pack with some 64-bit offsets'>)} 
      {(SQ <'git verify-pack -v "test-3-${pack3}.pack"'>)}
    )
    (C {<test_expect_success>} {<OFF64_T>} 
      {(SQ <'64-bit offsets: should be different from previous index v2 results'>)} {(SQ <'! cmp "test-2-${pack2}.idx" "test-3-${pack3}.idx"'>)}
    )
    (C {<test_expect_success>} {<OFF64_T>} {(SQ <'index v2: force some 64-bit offsets with index-pack'>)} 
      {(SQ <'git index-pack --index-version=2,0x40000 -o 3.idx "test-1-${pack1}.pack"'>)}
    )
    (C {<test_expect_success>} {<OFF64_T>} 
      {(SQ <'64-bit offsets: index-pack result should match pack-objects one'>)} {(SQ <'cmp "test-3-${pack3}.idx" "3.idx"'>)}
    )
    (C {<test_expect_success>} {<OFF64_T>} {(SQ <'index-pack --verify on 64-bit offset v2 (cheat)'>)} 
      {
        (SQ <'\n'> <'\t# This cheats by knowing which lower offset should still be encoded\n'> 
          <'\t# in 64-bit representation.\n'> <'\tgit index-pack --verify --index-version=2,0x40000 "test-3-${pack3}.pack"\n'>
        )
      }
    )
    (C {<test_expect_success>} {<OFF64_T>} {(SQ <'index-pack --verify on 64-bit offset v2'>)} 
      {(SQ <'\n'> <'\tgit index-pack --verify "test-3-${pack3}.pack"\n'>)}
    )
    (command.ShFunction
      name: index_obj_nr
      body: 
        (BraceGroup
          children: [
            (command.ShAssignment
              pairs: [
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:idx_file)
                  op: assign_op.Equal
                  rhs: {($ Id.VSub_Number '$1')}
                  spids: [399]
                )
              ]
            )
            (command.ShAssignment
              pairs: [
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:object_sha1)
                  op: assign_op.Equal
                  rhs: {($ Id.VSub_Number '$2')}
                  spids: [403]
                )
              ]
            )
            (command.ShAssignment
              pairs: [
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:nr)
                  op: assign_op.Equal
                  rhs: {<0>}
                  spids: [407]
                )
              ]
            )
            (command.Pipeline
              children: [
                (command.Simple
                  words: [{<git>} {<show-index>}]
                  redirects: [
                    (redir
                      op: <Id.Redir_Less '<'>
                      loc: (redir_loc.Fd fd:0)
                      arg: {($ Id.VSub_DollarName '$idx_file')}
                    )
                  ]
                  do_fork: T
                )
                (command.WhileUntil
                  keyword: <Id.KW_While while>
                  cond: [(C {<read>} {<offs>} {<sha1>} {<extra>})]
                  body: 
                    (command.DoGroup
                      children: [
                        (command.ShAssignment
                          pairs: [
                            (assign_pair
                              lhs: (sh_lhs_expr.Name name:nr)
                              op: assign_op.Equal
                              rhs: 
                                {
                                  (word_part.ArithSub
                                    anode: 
                                      (arith_expr.Binary
                                        op_id: Id.Arith_Plus
                                        left: {($ Id.VSub_DollarName '$nr')}
                                        right: {<Id.Lit_Digits 1>}
                                      )
                                  )
                                }
                              spids: [436]
                            )
                          ]
                        )
                        (command.AndOr
                          ops: [Id.Op_DPipe]
                          children: [
                            (C {<test>} {(DQ ($ Id.VSub_DollarName '$sha1'))} {<Id.Lit_Equals '='>} 
                              {(DQ ($ Id.VSub_DollarName '$object_sha1'))}
                            )
                            (command.ControlFlow
                              token: <Id.ControlFlow_Continue continue>
                            )
                          ]
                        )
                        (C {<echo>} 
                          {
                            (DQ 
                              (word_part.ArithSub
                                anode: 
                                  (arith_expr.Binary
                                    op_id: Id.Arith_Minus
                                    left: {($ Id.VSub_DollarName '$nr')}
                                    right: {<Id.Lit_Digits 1>}
                                  )
                              )
                            )
                          }
                        )
                        (command.ControlFlow
                          token: <Id.ControlFlow_Break break>
                        )
                      ]
                    )
                )
              ]
              negated: F
            )
          ]
        )
    )
    (command.ShFunction
      name: index_obj_offset
      body: 
        (BraceGroup
          children: [
            (command.ShAssignment
              pairs: [
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:idx_file)
                  op: assign_op.Equal
                  rhs: {($ Id.VSub_Number '$1')}
                  spids: [496]
                )
              ]
            )
            (command.ShAssignment
              pairs: [
                (assign_pair
                  lhs: (sh_lhs_expr.Name name:object_sha1)
                  op: assign_op.Equal
                  rhs: {($ Id.VSub_Number '$2')}
                  spids: [500]
                )
              ]
            )
            (command.Pipeline
              children: [
                (command.Simple
                  words: [{<git>} {<show-index>}]
                  redirects: [
                    (redir
                      op: <Id.Redir_Less '<'>
                      loc: (redir_loc.Fd fd:0)
                      arg: {($ Id.VSub_DollarName '$idx_file')}
                    )
                  ]
                  do_fork: T
                )
                (C {<grep>} {($ Id.VSub_DollarName '$object_sha1')})
                (command.Subshell
                  child: 
                    (command.AndOr
                      ops: [Id.Op_DAmp]
                      children: [
                        (C {<read>} {<offs>} {<extra>})
                        (C {<echo>} {(DQ ($ Id.VSub_DollarName '$offs'))})
                      ]
                    )
                )
              ]
              negated: F
            )
          ]
        )
    )
    (C {<test_expect_success>} {(SQ <'[index v1] 1) stream pack to repository'>)} 
      {
        (SQ <'git index-pack --index-version=1 --stdin < "test-1-${pack1}.pack" &&\n'> 
          <'     git prune-packed &&\n'> <'     git count-objects | ( read nr rest && test "$nr" -eq 1 ) &&\n'> 
          <'     cmp "test-1-${pack1}.pack" ".git/objects/pack/pack-${pack1}.pack" &&\n'> <'     cmp "test-1-${pack1}.idx"  ".git/objects/pack/pack-${pack1}.idx"'>
        )
      }
    )
    (C {<test_expect_success>} 
      {(SQ <'[index v1] 2) create a stealth corruption in a delta base reference'>)} 
      {
        (SQ <'# This test assumes file_101 is a delta smaller than 16 bytes.\n'> 
          <'     # It should be against file_100 but we substitute its base for file_099\n'> <'     sha1_101=$(git hash-object file_101) &&\n'> <'     sha1_099=$(git hash-object file_099) &&\n'> 
          <'     offs_101=$(index_obj_offset 1.idx $sha1_101) &&\n'> <'     nr_099=$(index_obj_nr 1.idx $sha1_099) &&\n'> 
          <'     chmod +w ".git/objects/pack/pack-${pack1}.pack" &&\n'> <'     dd of=".git/objects/pack/pack-${pack1}.pack" seek=$(($offs_101 + 1)) \\\n'> 
          <'        if=".git/objects/pack/pack-${pack1}.idx" \\\n'> <'        skip=$((4 + 256 * 4 + $nr_099 * 24)) \\\n'> <'        bs=1 count=20 conv=notrunc &&\n'> 
          <'     git cat-file blob $sha1_101 > file_101_foo1'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'[index v1] 3) corrupted delta happily returned wrong data'>)} 
      {(SQ <'test -f file_101_foo1 && ! cmp file_101 file_101_foo1'>)}
    )
    (C {<test_expect_success>} {(SQ <'[index v1] 4) confirm that the pack is actually corrupted'>)} 
      {(SQ <'test_must_fail git fsck --full $commit'>)}
    )
    (C {<test_expect_success>} {(SQ <'[index v1] 5) pack-objects happily reuses corrupted data'>)} 
      {
        (SQ <'pack4=$(git pack-objects test-4 <obj-list) &&\n'> 
          <'     test -f "test-4-${pack4}.pack"'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'[index v1] 6) newly created pack is BAD !'>)} 
      {(SQ <'test_must_fail git verify-pack -v "test-4-${pack4}.pack"'>)}
    )
    (C {<test_expect_success>} {(SQ <'[index v2] 1) stream pack to repository'>)} 
      {
        (SQ <'rm -f .git/objects/pack/* &&\n'> 
          <'     git index-pack --index-version=2 --stdin < "test-1-${pack1}.pack" &&\n'> <'     git prune-packed &&\n'> <'     git count-objects | ( read nr rest && test "$nr" -eq 1 ) &&\n'> 
          <'     cmp "test-1-${pack1}.pack" ".git/objects/pack/pack-${pack1}.pack" &&\n'> <'     cmp "test-2-${pack1}.idx"  ".git/objects/pack/pack-${pack1}.idx"'>
        )
      }
    )
    (C {<test_expect_success>} 
      {(SQ <'[index v2] 2) create a stealth corruption in a delta base reference'>)} 
      {
        (SQ <'# This test assumes file_101 is a delta smaller than 16 bytes.\n'> 
          <'     # It should be against file_100 but we substitute its base for file_099\n'> <'     sha1_101=$(git hash-object file_101) &&\n'> <'     sha1_099=$(git hash-object file_099) &&\n'> 
          <'     offs_101=$(index_obj_offset 1.idx $sha1_101) &&\n'> <'     nr_099=$(index_obj_nr 1.idx $sha1_099) &&\n'> 
          <'     chmod +w ".git/objects/pack/pack-${pack1}.pack" &&\n'> <'     dd of=".git/objects/pack/pack-${pack1}.pack" seek=$(($offs_101 + 1)) \\\n'> 
          <'        if=".git/objects/pack/pack-${pack1}.idx" \\\n'> <'        skip=$((8 + 256 * 4 + $nr_099 * 20)) \\\n'> <'        bs=1 count=20 conv=notrunc &&\n'> 
          <'     git cat-file blob $sha1_101 > file_101_foo2'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'[index v2] 3) corrupted delta happily returned wrong data'>)} 
      {(SQ <'test -f file_101_foo2 && ! cmp file_101 file_101_foo2'>)}
    )
    (C {<test_expect_success>} {(SQ <'[index v2] 4) confirm that the pack is actually corrupted'>)} 
      {(SQ <'test_must_fail git fsck --full $commit'>)}
    )
    (C {<test_expect_success>} {(SQ <'[index v2] 5) pack-objects refuses to reuse corrupted data'>)} 
      {
        (SQ <'test_must_fail git pack-objects test-5 <obj-list &&\n'> 
          <'     test_must_fail git pack-objects --no-reuse-object test-6 <obj-list'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'[index v2] 6) verify-pack detects CRC mismatch'>)} 
      {
        (SQ <'rm -f .git/objects/pack/* &&\n'> 
          <'     git index-pack --index-version=2 --stdin < "test-1-${pack1}.pack" &&\n'> <'     git verify-pack ".git/objects/pack/pack-${pack1}.pack" &&\n'> 
          <'     obj=$(git hash-object file_001) &&\n'> <'     nr=$(index_obj_nr ".git/objects/pack/pack-${pack1}.idx" $obj) &&\n'> 
          <'     chmod +w ".git/objects/pack/pack-${pack1}.idx" &&\n'> <'     printf xxxx | dd of=".git/objects/pack/pack-${pack1}.idx" conv=notrunc \\\n'> 
          <'        bs=1 count=4 seek=$((8 + 256 * 4 + $(wc -l <obj-list) * 20 + $nr * 4)) &&\n'> <'     ( while read obj\n'> <'       do git cat-file -p $obj >/dev/null || exit 1\n'> 
          <'       done <obj-list ) &&\n'> <'     test_must_fail git verify-pack ".git/objects/pack/pack-${pack1}.pack"\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'running index-pack in the object store'>)} 
      {
        (SQ <'\n'> <'    rm -f .git/objects/pack/* &&\n'> 
          <'    cp test-1-${pack1}.pack .git/objects/pack/pack-${pack1}.pack &&\n'> <'    (\n'> <'\tcd .git/objects/pack\n'> <'\tgit index-pack pack-${pack1}.pack\n'> <'    ) &&\n'> 
          <'    test -f .git/objects/pack/pack-${pack1}.idx\n'>
        )
      }
    )
    (C {<test_expect_success>} {(SQ <'index-pack --strict warns upon missing tagger in tag'>)} 
      {
        (SQ <'\n'> <'    sha=$(git rev-parse HEAD) &&\n'> <'    cat >wrong-tag <<EOF &&\n'> 
          <'object $sha\n'> <'type commit\n'> <'tag guten tag\n'> <'\n'> <'This is an invalid tag.\n'> <'EOF\n'> <'\n'> 
          <'    tag=$(git hash-object -t tag -w --stdin <wrong-tag) &&\n'> <'    pack1=$(echo $tag $sha | git pack-objects tag-test) &&\n'> <'    echo remove tag object &&\n'> 
          <'    thirtyeight=${tag#??} &&\n'> <'    rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight &&\n'> 
          <'    git index-pack --strict tag-test-${pack1}.pack 2>err &&\n'> <'    grep "^warning:.* expected .tagger. line" err\n'>
        )
      }
    )
    (C {<test_done>})
  ]
)