1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
#!/bin/bash
folder=tmp/a_repo
nodeI=0
function node() {
n=$nodeI
nodeI=$((nodeI+1))
touch $n >> /dev/null
git add $n >> /dev/null
if ! [ "$1" == "" ] ; then
n=$1
fi
git commit -m node-$n- >> /dev/null
if ! [ "$1" == "" ] ; then
git tag -m "" $n >> /dev/null
fi
}
function get_SHA1() {
git log --all --grep node-$1- | grep commit | sed -e 's/commit //'
}
function goto() {
SHA1=$(get_SHA1 $1)
git checkout $SHA1 -b $2 >> /dev/null
}
function merge() {
n=$nodeI
nodeI=$((nodeI+1))
SHA1=$(get_SHA1 $1)
git merge --no-ff $SHA1 -m node-$n- >> /dev/null
}
function range() {
i=$1
I=$2
res=$i
while [[ i -lt I ]] ; do
i=$((i+1))
res="$res $i"
done
echo $res
}
function nodes() {
I=$(($1-1))
for i in $(range 0 $I) ; do
node
done
}
rm -rf "$folder"
mkdir "$folder"
cd "$folder"
git init
git symbolic-ref HEAD refs/heads/main
# Tags are used to get difference between row and generation values.
# Branches main & b2 occupied 2 rows per generation because of tags.
# Branches b0 is at the left of tags. Therefore, b0 uses 1 row per generation.
# The same is for b1 too. The b1 is short but tag 'b1' cannot be placed
# right at the row the branch ends, because the tags at the right were already
# placed (they have less generation value). Hence, a gap between last two
# commits of b1 is big. Let b0 forks at a row inside the gap. The fork commit
# have greater generation than last commit of b1. Hence, it is placed after.
# Because of the bug, making many enough branches starting from the fork will
# manage to overlapping of last commit of b1 and a commit of a branch.
node tag0
node tag1
node tag2
node tag3
node tag4
nodes 1
goto tag0 b0
nodes 8
b0_head=$n
goto tag0 b1
nodes 5
goto tag0 b2
nodes 10
git checkout b0
nodes 5
goto $b0_head b5
nodes 5
goto $b0_head b6
nodes 5
goto $b0_head b7
nodes 5
git checkout b2
../../../bin/git-dag --all &
|