t / t5318-commit-graph.shon commit pack-objects: document about thread synchronization (ffbd51c)
   1#!/bin/sh
   2
   3test_description='commit graph'
   4. ./test-lib.sh
   5
   6test_expect_success 'setup full repo' '
   7        mkdir full &&
   8        cd "$TRASH_DIRECTORY/full" &&
   9        git init &&
  10        git config core.commitGraph true &&
  11        objdir=".git/objects"
  12'
  13
  14test_expect_success 'write graph with no packs' '
  15        cd "$TRASH_DIRECTORY/full" &&
  16        git commit-graph write --object-dir . &&
  17        test_path_is_file info/commit-graph
  18'
  19
  20test_expect_success 'create commits and repack' '
  21        cd "$TRASH_DIRECTORY/full" &&
  22        for i in $(test_seq 3)
  23        do
  24                test_commit $i &&
  25                git branch commits/$i
  26        done &&
  27        git repack
  28'
  29
  30graph_git_two_modes() {
  31        git -c core.graph=true $1 >output
  32        git -c core.graph=false $1 >expect
  33        test_cmp output expect
  34}
  35
  36graph_git_behavior() {
  37        MSG=$1
  38        DIR=$2
  39        BRANCH=$3
  40        COMPARE=$4
  41        test_expect_success "check normal git operations: $MSG" '
  42                cd "$TRASH_DIRECTORY/$DIR" &&
  43                graph_git_two_modes "log --oneline $BRANCH" &&
  44                graph_git_two_modes "log --topo-order $BRANCH" &&
  45                graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
  46                graph_git_two_modes "branch -vv" &&
  47                graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
  48        '
  49}
  50
  51graph_git_behavior 'no graph' full commits/3 commits/1
  52
  53graph_read_expect() {
  54        OPTIONAL=""
  55        NUM_CHUNKS=3
  56        if test ! -z $2
  57        then
  58                OPTIONAL=" $2"
  59                NUM_CHUNKS=$((3 + $(echo "$2" | wc -w)))
  60        fi
  61        cat >expect <<- EOF
  62        header: 43475048 1 1 $NUM_CHUNKS 0
  63        num_commits: $1
  64        chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
  65        EOF
  66        git commit-graph read >output &&
  67        test_cmp expect output
  68}
  69
  70test_expect_success 'write graph' '
  71        cd "$TRASH_DIRECTORY/full" &&
  72        graph1=$(git commit-graph write) &&
  73        test_path_is_file $objdir/info/commit-graph &&
  74        graph_read_expect "3"
  75'
  76
  77graph_git_behavior 'graph exists' full commits/3 commits/1
  78
  79test_expect_success 'Add more commits' '
  80        cd "$TRASH_DIRECTORY/full" &&
  81        git reset --hard commits/1 &&
  82        for i in $(test_seq 4 5)
  83        do
  84                test_commit $i &&
  85                git branch commits/$i
  86        done &&
  87        git reset --hard commits/2 &&
  88        for i in $(test_seq 6 7)
  89        do
  90                test_commit $i &&
  91                git branch commits/$i
  92        done &&
  93        git reset --hard commits/2 &&
  94        git merge commits/4 &&
  95        git branch merge/1 &&
  96        git reset --hard commits/4 &&
  97        git merge commits/6 &&
  98        git branch merge/2 &&
  99        git reset --hard commits/3 &&
 100        git merge commits/5 commits/7 &&
 101        git branch merge/3 &&
 102        git repack
 103'
 104
 105# Current graph structure:
 106#
 107#   __M3___
 108#  /   |   \
 109# 3 M1 5 M2 7
 110# |/  \|/  \|
 111# 2    4    6
 112# |___/____/
 113# 1
 114
 115test_expect_success 'write graph with merges' '
 116        cd "$TRASH_DIRECTORY/full" &&
 117        git commit-graph write &&
 118        test_path_is_file $objdir/info/commit-graph &&
 119        graph_read_expect "10" "large_edges"
 120'
 121
 122graph_git_behavior 'merge 1 vs 2' full merge/1 merge/2
 123graph_git_behavior 'merge 1 vs 3' full merge/1 merge/3
 124graph_git_behavior 'merge 2 vs 3' full merge/2 merge/3
 125
 126test_expect_success 'Add one more commit' '
 127        cd "$TRASH_DIRECTORY/full" &&
 128        test_commit 8 &&
 129        git branch commits/8 &&
 130        ls $objdir/pack | grep idx >existing-idx &&
 131        git repack &&
 132        ls $objdir/pack| grep idx | grep -v --file=existing-idx >new-idx
 133'
 134
 135# Current graph structure:
 136#
 137#      8
 138#      |
 139#   __M3___
 140#  /   |   \
 141# 3 M1 5 M2 7
 142# |/  \|/  \|
 143# 2    4    6
 144# |___/____/
 145# 1
 146
 147graph_git_behavior 'mixed mode, commit 8 vs merge 1' full commits/8 merge/1
 148graph_git_behavior 'mixed mode, commit 8 vs merge 2' full commits/8 merge/2
 149
 150test_expect_success 'write graph with new commit' '
 151        cd "$TRASH_DIRECTORY/full" &&
 152        git commit-graph write &&
 153        test_path_is_file $objdir/info/commit-graph &&
 154        graph_read_expect "11" "large_edges"
 155'
 156
 157graph_git_behavior 'full graph, commit 8 vs merge 1' full commits/8 merge/1
 158graph_git_behavior 'full graph, commit 8 vs merge 2' full commits/8 merge/2
 159
 160test_expect_success 'write graph with nothing new' '
 161        cd "$TRASH_DIRECTORY/full" &&
 162        git commit-graph write &&
 163        test_path_is_file $objdir/info/commit-graph &&
 164        graph_read_expect "11" "large_edges"
 165'
 166
 167graph_git_behavior 'cleared graph, commit 8 vs merge 1' full commits/8 merge/1
 168graph_git_behavior 'cleared graph, commit 8 vs merge 2' full commits/8 merge/2
 169
 170test_expect_success 'build graph from latest pack with closure' '
 171        cd "$TRASH_DIRECTORY/full" &&
 172        cat new-idx | git commit-graph write --stdin-packs &&
 173        test_path_is_file $objdir/info/commit-graph &&
 174        graph_read_expect "9" "large_edges"
 175'
 176
 177graph_git_behavior 'graph from pack, commit 8 vs merge 1' full commits/8 merge/1
 178graph_git_behavior 'graph from pack, commit 8 vs merge 2' full commits/8 merge/2
 179
 180test_expect_success 'build graph from commits with closure' '
 181        cd "$TRASH_DIRECTORY/full" &&
 182        git tag -a -m "merge" tag/merge merge/2 &&
 183        git rev-parse tag/merge >commits-in &&
 184        git rev-parse merge/1 >>commits-in &&
 185        cat commits-in | git commit-graph write --stdin-commits &&
 186        test_path_is_file $objdir/info/commit-graph &&
 187        graph_read_expect "6"
 188'
 189
 190graph_git_behavior 'graph from commits, commit 8 vs merge 1' full commits/8 merge/1
 191graph_git_behavior 'graph from commits, commit 8 vs merge 2' full commits/8 merge/2
 192
 193test_expect_success 'build graph from commits with append' '
 194        cd "$TRASH_DIRECTORY/full" &&
 195        git rev-parse merge/3 | git commit-graph write --stdin-commits --append &&
 196        test_path_is_file $objdir/info/commit-graph &&
 197        graph_read_expect "10" "large_edges"
 198'
 199
 200graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
 201graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
 202
 203test_expect_success 'setup bare repo' '
 204        cd "$TRASH_DIRECTORY" &&
 205        git clone --bare --no-local full bare &&
 206        cd bare &&
 207        git config core.commitGraph true &&
 208        baredir="./objects"
 209'
 210
 211graph_git_behavior 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1
 212graph_git_behavior 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2
 213
 214test_expect_success 'write graph in bare repo' '
 215        cd "$TRASH_DIRECTORY/bare" &&
 216        git commit-graph write &&
 217        test_path_is_file $baredir/info/commit-graph &&
 218        graph_read_expect "11" "large_edges"
 219'
 220
 221graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1
 222graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2
 223
 224test_done