t / perf / repos / inflate-repo.shon commit Merge branch 'ah/doc-wserrorhighlight' (4c244c2)
   1#!/bin/sh
   2# Inflate the size of an EXISTING repo.
   3#
   4# This script should be run inside the worktree of a TEST repo.
   5# It will use the contents of the current HEAD to generate a
   6# commit containing copies of the current worktree such that the
   7# total size of the commit has at least <target_size> files.
   8#
   9# Usage: [-t target_size] [-b branch_name]
  10
  11set -e
  12
  13target_size=10000
  14branch_name=p0006-ballast
  15ballast=ballast
  16
  17while test "$#" -ne 0
  18do
  19    case "$1" in
  20        -b)
  21            shift;
  22            test "$#" -ne 0 || { echo 'error: -b requires an argument' >&2; exit 1; }
  23            branch_name=$1;
  24            shift ;;
  25        -t)
  26            shift;
  27            test "$#" -ne 0 || { echo 'error: -t requires an argument' >&2; exit 1; }
  28            target_size=$1;
  29            shift ;;
  30        *)
  31            echo "error: unknown option '$1'" >&2; exit 1 ;;
  32    esac
  33done
  34
  35git ls-tree -r HEAD >GEN_src_list
  36nr_src_files=$(cat GEN_src_list | wc -l)
  37
  38src_branch=$(git symbolic-ref --short HEAD)
  39
  40echo "Branch $src_branch initially has $nr_src_files files."
  41
  42if test $target_size -le $nr_src_files
  43then
  44    echo "Repository already exceeds target size $target_size."
  45    rm GEN_src_list
  46    exit 1
  47fi
  48
  49# Create well-known branch and add 1 file change to start
  50# if off before the ballast.
  51git checkout -b $branch_name HEAD
  52echo "$target_size" > inflate-repo.params
  53git add inflate-repo.params
  54git commit -q -m params
  55
  56# Create ballast for in our branch.
  57copy=1
  58nr_files=$nr_src_files
  59while test $nr_files -lt $target_size
  60do
  61    sed -e "s|  |       $ballast/$copy/|" <GEN_src_list |
  62        git update-index --index-info
  63
  64    nr_files=$(expr $nr_files + $nr_src_files)
  65    copy=$(expr $copy + 1)
  66done
  67rm GEN_src_list
  68git commit -q -m "ballast"
  69
  70# Modify 1 file and commit.
  71echo "$target_size" >> inflate-repo.params
  72git add inflate-repo.params
  73git commit -q -m "ballast plus 1"
  74
  75nr_files=$(git ls-files | wc -l)
  76
  77# Checkout master to put repo in canonical state (because
  78# the perf test may need to clone and enable sparse-checkout
  79# before attempting to checkout a commit with the ballast
  80# (because it may contain 100K directories and 1M files)).
  81git checkout $src_branch
  82
  83echo "Repository inflated. Branch $branch_name has $nr_files files."
  84
  85exit 0