Skip to content

Commit 2a24250

Browse files
committed
Manually create tag if 32-bit git rejects it
This is a workaround for the problem where `git tag` rejects the timestamp `4147483646` from `generation_number_overflow.sh` as out of range, even though it has already been accepted to create a commit and `git tag` is obtaining it from the commit metadata. The test already passed if run without `GIX_TEST_IGNORE_ARCHIVES`, even though the commit and tag metadata in the committed archive repo has this timestamp interpreted as from 1970 rather than in the far future. The change here just allows the fixture script to create the repository on a 32-bit system where `git` would refuse to make the tag, by manually creating a loose tag. (Creating a packed tag would also work, but would not improve the ambiguity.)
1 parent 595929b commit 2a24250

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -eu -o pipefail
33

4-
function tick () {
4+
function tick() {
55
if test -z "${tick+set}"
66
then
77
tick=1112911993
@@ -13,9 +13,25 @@ function tick () {
1313
export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
1414
}
1515

16-
tick
17-
function commit() {
18-
local message=${1:?first argument is the commit message}
16+
function force_tag() {
17+
local name head_oid common_dir
18+
name=${1:?argument the tag name}
19+
20+
# This should only be needed with 32-bit `git`, so fail otherwise.
21+
word_size="$(
22+
git --version --build-options |
23+
awk '$1 == "sizeof-size_t:" { print $2 }'
24+
)"
25+
((word_size == 4))
26+
27+
# Manually create the tag.
28+
head_oid="$(git rev-parse HEAD)"
29+
common_dir="$(git rev-parse --git-common-dir)"
30+
(set -o noclobber; echo "$head_oid" > "$common_dir/refs/tags/$name")
31+
}
32+
33+
function tagged_commit() {
34+
local message=${1:?first argument is the commit message and tag name}
1935
local date=${2:-}
2036
local file="$message.t"
2137
echo "$1" > "$file"
@@ -26,23 +42,24 @@ function commit() {
2642
tick
2743
fi
2844
git commit -m "$message"
29-
git tag "$message"
45+
git tag -- "$message" || force_tag "$message"
3046
}
3147

48+
tick
49+
3250
# adapted from git/t/t5318 'lower layers have overflow chunk'
3351
UNIX_EPOCH_ZERO="@0 +0000"
3452
FUTURE_DATE="@4147483646 +0000"
3553

3654
git init
3755
git config commitGraph.generationVersion 2
3856

39-
set -x
40-
commit future-1 "$FUTURE_DATE"
41-
commit old-1 "$UNIX_EPOCH_ZERO"
57+
tagged_commit future-1 "$FUTURE_DATE"
58+
tagged_commit old-1 "$UNIX_EPOCH_ZERO"
4259
git commit-graph write --reachable
43-
commit future-2 "$FUTURE_DATE"
44-
commit old-2 "$UNIX_EPOCH_ZERO"
60+
tagged_commit future-2 "$FUTURE_DATE"
61+
tagged_commit old-2 "$UNIX_EPOCH_ZERO"
4562
git commit-graph write --reachable --split=no-merge
46-
commit extra
63+
tagged_commit extra
4764
# this makes sure it's actually in chain format.
4865
git commit-graph write --reachable --split=no-merge

0 commit comments

Comments
 (0)