Skip to content

Commit 17925e0

Browse files
derrickstoleegitster
authored andcommitted
t5318: extract helpers to lib-commit-graph.sh
The graph_git_behavior helper is useful for testing that certain Git commands behave the same when using the commit-graph and when not using the commit-graph. Extract it to a new lib-commit-graph.sh file for use in new test scripts that will split out from t5318. While doing this extraction, also extract graph_read_expect and the logic for priming the test_oid_cache. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c78c7a9 commit 17925e0

File tree

2 files changed

+50
-48
lines changed

2 files changed

+50
-48
lines changed

t/lib-commit-graph.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
3+
# Helper functions for testing commit-graphs.
4+
5+
# Initialize OID cache with oid_version
6+
test_oid_cache <<-EOF
7+
oid_version sha1:1
8+
oid_version sha256:2
9+
EOF
10+
11+
graph_git_two_modes() {
12+
git -c core.commitGraph=true $1 >output &&
13+
git -c core.commitGraph=false $1 >expect &&
14+
test_cmp expect output
15+
}
16+
17+
graph_git_behavior() {
18+
MSG=$1
19+
DIR=$2
20+
BRANCH=$3
21+
COMPARE=$4
22+
test_expect_success "check normal git operations: $MSG" '
23+
cd "$TRASH_DIRECTORY/$DIR" &&
24+
graph_git_two_modes "log --oneline $BRANCH" &&
25+
graph_git_two_modes "log --topo-order $BRANCH" &&
26+
graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
27+
graph_git_two_modes "branch -vv" &&
28+
graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
29+
'
30+
}
31+
32+
graph_read_expect() {
33+
OPTIONAL=""
34+
NUM_CHUNKS=3
35+
if test -n "$2"
36+
then
37+
OPTIONAL=" $2"
38+
NUM_CHUNKS=$((3 + $(echo "$2" | wc -w)))
39+
fi
40+
cat >expect <<- EOF
41+
header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0
42+
num_commits: $1
43+
chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
44+
options:
45+
EOF
46+
test-tool read-graph >output &&
47+
test_cmp expect output
48+
}

t/t5318-commit-graph.sh

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ test_expect_success 'setup full repo' '
2929
cd "$TRASH_DIRECTORY/full" &&
3030
git init &&
3131
git config core.commitGraph true &&
32-
objdir=".git/objects" &&
33-
34-
test_oid_cache <<-EOF
35-
oid_version sha1:1
36-
oid_version sha256:2
37-
EOF
32+
objdir=".git/objects"
3833
'
3934

4035
test_expect_success POSIXPERM 'tweak umask for modebit tests' '
@@ -69,47 +64,10 @@ test_expect_success 'create commits and repack' '
6964
git repack
7065
'
7166

72-
graph_git_two_modes() {
73-
git -c core.commitGraph=true $1 >output &&
74-
git -c core.commitGraph=false $1 >expect &&
75-
test_cmp expect output
76-
}
77-
78-
graph_git_behavior() {
79-
MSG=$1
80-
DIR=$2
81-
BRANCH=$3
82-
COMPARE=$4
83-
test_expect_success "check normal git operations: $MSG" '
84-
cd "$TRASH_DIRECTORY/$DIR" &&
85-
graph_git_two_modes "log --oneline $BRANCH" &&
86-
graph_git_two_modes "log --topo-order $BRANCH" &&
87-
graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
88-
graph_git_two_modes "branch -vv" &&
89-
graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
90-
'
91-
}
67+
. "$TEST_DIRECTORY"/lib-commit-graph.sh
9268

9369
graph_git_behavior 'no graph' full commits/3 commits/1
9470

95-
graph_read_expect() {
96-
OPTIONAL=""
97-
NUM_CHUNKS=3
98-
if test ! -z "$2"
99-
then
100-
OPTIONAL=" $2"
101-
NUM_CHUNKS=$((3 + $(echo "$2" | wc -w)))
102-
fi
103-
cat >expect <<- EOF
104-
header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0
105-
num_commits: $1
106-
chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
107-
options:
108-
EOF
109-
test-tool read-graph >output &&
110-
test_cmp expect output
111-
}
112-
11371
test_expect_success 'exit with correct error on bad input to --stdin-commits' '
11472
cd "$TRASH_DIRECTORY/full" &&
11573
# invalid, non-hex OID
@@ -826,10 +784,6 @@ test_expect_success 'set up and verify repo with generation data overflow chunk'
826784
objdir=".git/objects" &&
827785
UNIX_EPOCH_ZERO="@0 +0000" &&
828786
FUTURE_DATE="@2147483646 +0000" &&
829-
test_oid_cache <<-EOF &&
830-
oid_version sha1:1
831-
oid_version sha256:2
832-
EOF
833787
cd "$TRASH_DIRECTORY" &&
834788
mkdir repo &&
835789
cd repo &&

0 commit comments

Comments
 (0)