Skip to content

Fix generation_number_overflow 32-bit tag creation #1698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ jobs:
- name: Make `system` scope nonempty for "GitInstallation" tests
run: git config --system gitoxide.imaginary.arbitraryVariable arbitraryValue
- name: Test (nextest)
env:
GIX_TEST_IGNORE_ARCHIVES: '1'
run: cargo nextest run --workspace --no-fail-fast

test-32bit-cross:
Expand Down
Binary file not shown.
38 changes: 28 additions & 10 deletions gix-commitgraph/tests/fixtures/generation_number_overflow.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -eu -o pipefail

function tick () {
function tick() {
if test -z "${tick+set}"
then
tick=1112911993
Expand All @@ -13,9 +13,25 @@ function tick () {
export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
}

tick
function commit() {
local message=${1:?first argument is the commit message}
function force_tag() {
Copy link
Member Author

@EliahKagan EliahKagan Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be named something else. Calling it force_tag makes it sound like it does something similar to git tag -f, when actually:

  • force_tag tries (though not very hard) to avoid resetting an existing tag.
  • git tag -f will still refuse to create a tag in the scenarios where this is intended to be called (or I would've just used git tag -f).

(I had meant to bring this up before the PR was merged, but forgot.)

local name head_oid common_dir
name=${1:?argument the tag name}

# This should only be needed with 32-bit `git`, so fail otherwise.
word_size="$(
git --version --build-options |
awk '$1 == "sizeof-size_t:" { print $2 }'
)"
((word_size == 4))

# Manually create the tag.
head_oid="$(git rev-parse HEAD)"
common_dir="$(git rev-parse --git-common-dir)"
(set -o noclobber; echo "$head_oid" > "$common_dir/refs/tags/$name")
}

function tagged_commit() {
local message=${1:?first argument is the commit message and tag name}
local date=${2:-}
local file="$message.t"
echo "$1" > "$file"
Expand All @@ -26,22 +42,24 @@ function commit() {
tick
fi
git commit -m "$message"
git tag "$message"
git tag -- "$message" || force_tag "$message"
}

tick

# adapted from git/t/t5318 'lower layers have overflow chunk'
UNIX_EPOCH_ZERO="@0 +0000"
FUTURE_DATE="@4147483646 +0000"

git init
git config commitGraph.generationVersion 2

commit future-1 "$FUTURE_DATE"
commit old-1 "$UNIX_EPOCH_ZERO"
tagged_commit future-1 "$FUTURE_DATE"
tagged_commit old-1 "$UNIX_EPOCH_ZERO"
git commit-graph write --reachable
commit future-2 "$FUTURE_DATE"
commit old-2 "$UNIX_EPOCH_ZERO"
tagged_commit future-2 "$FUTURE_DATE"
tagged_commit old-2 "$UNIX_EPOCH_ZERO"
git commit-graph write --reachable --split=no-merge
commit extra
tagged_commit extra
# this makes sure it's actually in chain format.
git commit-graph write --reachable --split=no-merge
Loading