| 1 |
#!/bin/bash |
| 2 |
#emacs: -*- mode: shell-script; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- |
| 3 |
#ex: set sts=4 ts=4 sw=4 noet: |
| 4 |
# |
| 5 |
# |
| 6 |
# COPYRIGHT: Yaroslav Halchenko 2014 |
| 7 |
# |
| 8 |
# LICENSE: MIT |
| 9 |
# |
| 10 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 |
# of this software and associated documentation files (the "Software"), to deal |
| 12 |
# in the Software without restriction, including without limitation the rights |
| 13 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 |
# copies of the Software, and to permit persons to whom the Software is |
| 15 |
# furnished to do so, subject to the following conditions: |
| 16 |
# |
| 17 |
# The above copyright notice and this permission notice shall be included in |
| 18 |
# all copies or substantial portions of the Software. |
| 19 |
# |
| 20 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 23 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 26 |
# THE SOFTWARE. |
| 27 |
# |
| 28 |
|
| 29 |
set -eu |
| 30 |
|
| 31 |
depth=5 |
| 32 |
# precreate associative array with directory names |
| 33 |
declare -A dirs |
| 34 |
dirs["0"]='.' |
| 35 |
dname=. |
| 36 |
for d in `eval echo {1..$depth}`; do |
| 37 |
echo $dname |
| 38 |
dname+="/d$d" |
| 39 |
dirs["$d"]=$dname |
| 40 |
done |
| 41 |
|
| 42 |
function multi_branch { |
| 43 |
branches=$1 |
| 44 |
files_per_branch=$2 |
| 45 |
annex=$3 |
| 46 |
echo "Creating $branches branches with $files_per_branch per branch. annex=$annex" |
| 47 |
i=0 |
| 48 |
for b in `eval echo {1..$branches}`; do |
| 49 |
git co -b b$b master &> /dev/null |
| 50 |
for f in `eval echo {1..$files_per_branch}`; do |
| 51 |
#echo -ne "\rFile $f" |
| 52 |
fdepth=$(python -c "print $i%$depth") |
| 53 |
dname=${dirs["$fdepth"]} |
| 54 |
#[ -e $dname ] || mkdir -p $dname |
| 55 |
fname=$dname/f$i.dat |
| 56 |
echo "file $i" > $fname; |
| 57 |
i=$(($i+1)) |
| 58 |
done |
| 59 |
if [ $annex=1 ]; then |
| 60 |
git annex add * > /dev/null; |
| 61 |
else |
| 62 |
git add * > /dev/null |
| 63 |
fi |
| 64 |
git commit -m "commit in branch $b" >/dev/null; |
| 65 |
done |
| 66 |
echo "Merging" |
| 67 |
eval "git merge -m 'merging $branches together' b{1..$branches}" >/dev/null |
| 68 |
} |
| 69 |
|
| 70 |
function init_repo { |
| 71 |
tdir_=$1 |
| 72 |
if [ -e $tdir_ ]; then |
| 73 |
chmod +w -R $tdir_ |
| 74 |
rm -r $tdir_ || : |
| 75 |
fi |
| 76 |
mkdir -p $tdir_ |
| 77 |
cd $tdir_ |
| 78 |
git init |
| 79 |
git annex init |
| 80 |
touch .empty |
| 81 |
git add .empty; git commit -m "initial commit just to avoid dances with empty branches" |
| 82 |
# precreate directories |
| 83 |
for d in ${dirs[*]}; do |
| 84 |
mkdir -p $tdir_/$d |
| 85 |
done |
| 86 |
} |
| 87 |
|
| 88 |
if [ $# -lt 2 ]; then |
| 89 |
echo "Usage: $0 nfiles_per_branch nbranches [tempdir]" |
| 90 |
exit 1 |
| 91 |
fi |
| 92 |
|
| 93 |
filespb=$1 |
| 94 |
br=$2 |
| 95 |
files=$(python -c "print $filespb*$br") |
| 96 |
|
| 97 |
if [ $# -ge 3 ]; then |
| 98 |
tdir=$3 |
| 99 |
else |
| 100 |
tdir=/tmp/testdir |
| 101 |
fi |
| 102 |
|
| 103 |
annex=0 |
| 104 |
echo "Temp path $tdir" |
| 105 |
init_repo $tdir/branches; cd $tdir/branches; time multi_branch $br $filespb $annex |
| 106 |
init_repo $tdir/nobranches; cd $tdir/nobranches; time multi_branch 1 $files $annex |
| 107 |
|
| 108 |
#init_repo |
| 109 |
#time singe_branch |