Skip to content

Commit

Permalink
add remaining baseline tests along with permutations
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 26, 2024
1 parent e97f90b commit a6b4db3
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 11 deletions.
Binary file not shown.
165 changes: 154 additions & 11 deletions gix-revision/tests/fixtures/make_merge_base_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -eu -o pipefail
git init

EMPTY_TREE=$(git mktree </dev/null)
function mkcommit () {
function ofs_commit () {
local OFFSET_SECONDS=$1
local COMMIT_NAME=$2
shift 2
Expand Down Expand Up @@ -33,8 +33,8 @@ function baseline() {

# Merge-bases adapted from Git test suite
# No merge base
mkcommit 0 DA
mkcommit 100 DB
ofs_commit 0 DA
ofs_commit 100 DB
{
echo "just-one-returns-one-in-code"
echo $(git rev-parse DA)
Expand All @@ -52,19 +52,20 @@ mkcommit 100 DB
# \ `---------G \
# \ \
# F----------------H
E=$(mkcommit 5 E)
D=$(mkcommit 4 D $E)
F=$(mkcommit 6 F $E)
C=$(mkcommit 3 C $D)
B=$(mkcommit 2 B $C)
A=$(mkcommit 1 A $B)
G=$(mkcommit 7 G $B $E)
H=$(mkcommit 8 H $A $F)
E=$(ofs_commit 5 E)
D=$(ofs_commit 4 D $E)
F=$(ofs_commit 6 F $E)
C=$(ofs_commit 3 C $D)
B=$(ofs_commit 2 B $C)
A=$(ofs_commit 1 A $B)
G=$(ofs_commit 7 G $B $E)
H=$(ofs_commit 8 H $A $F)

{
baseline G H
} > 2_a.baseline

# Permutation testing - let's do it early to avoid too many permutations
commits=$(git log --all --format=%s)
commit_array=($commits)
num_commits=${#commit_array[@]}
Expand All @@ -75,5 +76,147 @@ for ((i=0; i<num_commits; i++)); do
done
done > 3_permutations.baseline

# Timestamps cannot be trusted.
#
# Relative
# Structure timestamps
#
# PL PR +4 +4
# / \/ \ / \/ \
# L2 C2 R2 +3 -1 +3
# | | | | | |
# L1 C1 R1 +2 -2 +2
# | | | | | |
# L0 C0 R0 +1 -3 +1
# \ | / \ | /
# S 0
#
# The left and right chains of commits can be of any length and complexity as
# long as all of the timestamps are greater than that of S.
S=$(ofs_commit 0 S)

C0=$(ofs_commit -3 C0 $S)
C1=$(ofs_commit -2 C1 $C0)
C2=$(ofs_commit -1 C2 $C1)

L0=$(ofs_commit 1 L0 $S)
L1=$(ofs_commit 2 L1 $L0)
L2=$(ofs_commit 3 L2 $L1)

R0=$(ofs_commit 1 R0 $S)
R1=$(ofs_commit 2 R1 $R0)
R2=$(ofs_commit 3 R2 $R1)

PL=$(ofs_commit 4 PL $L2 $C2)
PR=$(ofs_commit 4 PR $C2 $R2)

{
baseline PL PR
} > 4_b.baseline


function tick () {
if test -z "${tick+set}"
then
tick=1112911993
else
tick=$(($tick + 60))
fi
GIT_COMMITTER_DATE="$tick -0700"
GIT_AUTHOR_DATE="$tick -0700"
export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
}

tick
function commit() {
local message=${1:?first argument is the commit message}
local date=${2:-}
if [ -n "$date" ]; then
export GIT_COMMITTER_DATE="$date"
else
tick
fi
git commit --allow-empty -m "$message"
git tag "$message"
}

# * C (MMC) * B (MMB) * A (MMA)
# * o * o * o
# * o * o * o
# * o * o * o
# * o | _______/
# | |/
# | * 1 (MM1)
# | _______/
# |/
# * root (MMR)

commit MMR
commit MM1
commit MM-o
commit MM-p
commit MM-q
commit MMA
git checkout MM1
commit MM-r
commit MM-s
commit MM-t
commit MMB
git checkout MMR
commit MM-u
commit MM-v
commit MM-w
commit MM-x
commit MMC

{
baseline MMA MMB MMC
} > 5_c.baseline

merge () {
label="$1"
shift
tick
git merge -m "$label" "$@"
git tag "$label"
}

# JE
# / |
# / |
# / |
# JAA / |
# |\ / |
# | \ | JDD |
# | \ |/ | |
# | JC JD |
# | | /| |
# | |/ | |
# JA | | |
# |\ /| | |
# X JB | X X
# \ \ | / /
# \__\|/___/
# J
commit J
commit JB
git reset --hard J
commit JC
git reset --hard J
commit JTEMP1
merge JA JB
merge JAA JC
git reset --hard J
commit JTEMP2
merge JD JB
merge JDD JC
git reset --hard J
commit JTEMP3
merge JE JC

{
baseline JAA JDD JE
} > 5_c.baseline

git commit-graph write --no-progress --reachable
git repack -adq

0 comments on commit a6b4db3

Please sign in to comment.