Skip to content

Commit 132d912

Browse files
codexByron
authored andcommitted
fix(gix): preserve Git's handling of negative identity dates
Git 2.54 parses only unsigned timestamp digits in an identity. The GixPython 0.4.0 accessor can return a negative timestamp and a nonzero offset from a header with trailing fields. Use the existing CLI fallback for negative native timestamps so object properties keep the established zero date and offset. The deserialization suite passed on both backends, including author, committer and tagger checks for the negative timestamp. Agent-Model: unknown
1 parent 6f7a070 commit 132d912

4 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎doc/gix-backend.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ identify the historical fixture where needed.
10151015
| GIX-39 | Bug (open) | On Git 2.54.0, `git rev-parse --verify HEAD@{never}` rejects the date. GixPython 0.4.0's `Repository.rev_parse_single()` returns the oldest commit. With reflog entries 80, 52, 49, 40, 3 and 0 hours old, Git also selects the 80-hour entry for `HEAD@{2days3hours}`, while Gix selects the 52-hour entry. | Match Git's approxidate grammar and invalid-date handling. `_check_revision_grammar()` retains CLI for textual selectors. `test_rev_parse_reflog_selectors` covers a rejected date, an accepted date and ordinary reflog selectors. |
10161016
| GIX-40 | Bug (open) | With Git 2.54.0 and GixPython 0.4.0, `gix-backend.sh embedded_status_uses_git_diff_policy` tracks a gitlink without a `.gitmodules` entry. An untracked file in its checkout leaves `git diff --raw` empty, but native configured status reports a `SubmoduleModification` with `superproject_configuration` false. Both report changes to tracked files in the embedded checkout. The fixture covers SHA-1 and SHA-256. | Expose Git's diff ignore policy for embedded repositories. `Repo.is_dirty()` uses Git when native worktree status reports a modification in an embedded repository. |
10171017
| GIX-41 | Bug (open) | With Git 2.54.0 and GixPython 0.4.0, `tree-modes.sh` writes an entry with either an empty mode field or the literal `0`. Both are decoded by `Tree.iter()` as mode zero and kind `commit`. Git rejects the empty field with `malformed mode in tree entry` and lists the literal zero as a gitlink. `test_ambiguous_tree_entry_mode_uses_git` verifies both results for SHA-1 and SHA-256. | Reject a missing mode or expose the distinction between a missing mode and an encoded zero. `_ls_tree()` defers mode zero to Git for validation and formatting. |
1018+
| GIX-42 | Bug (open) | With Git 2.54.0 and GixPython 0.4.0, `commit.sh negative-date` stores `-1 +0200 1700000000 -0500` in the author, committer and tagger identities. Git's `split_ident_line()` requires unsigned timestamp digits, so `git show --format=%ad --date=raw` reports no date and GitPython's CLI path returns `(0, 0)`. Native signature accessors expose `(-1, +7200)` as seconds and offset east of UTC. | Provide Git-compatible negative timestamp handling. `object_metadata()` retains CLI for negative dates. `test_deserialization_negative_timestamp_matches_git` verifies both object kinds. |
10181019

10191020
GIX-14 also covers configured worktree symlink resolution. On macOS with
10201021
GixPython 0.3.0, CPython 3.12.14 and Git 2.54.0, set a submodule's

‎git/_backend.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ def object_metadata(command: Any, oid: str, kind: str) -> Any:
255255
)
256256
for raw, signature in signatures:
257257
if signature is not None:
258+
if signature.time.seconds < 0:
259+
raise _Unsupported("negative signature timestamp (GIX-42)")
258260
# Gix can decode a short offset such as +020 as UTC.
259261
date = raw.rpartition(b">")[2].replace(b" -0000", b" +0000", 1)
260262
if not (date + b" ").startswith(b" " + _date(signature) + b" "):

‎test/test_commit.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,23 @@ def test_deserialization_reads_date_after_email(self):
706706
key = (kind + ".decode", "native")
707707
self.assertEqual(_backend.statistics().get(key, 0), before.get(key, 0) + 1)
708708

709+
def test_deserialization_negative_timestamp_matches_git(self):
710+
with fixture_repo("commit.sh", "negative-date") as repo:
711+
root = Path(repo.working_dir).parent
712+
oid = (root / "object-id").read_text().strip()
713+
tag_oid = (root / "tag-id").read_text().strip()
714+
self.assertEqual(repo.git.show("-s", "--format=%ad", "--date=raw", oid), "")
715+
before = _backend.statistics()
716+
commit = Commit(repo, bytes.fromhex(oid))
717+
self.assertEqual((commit.authored_date, commit.author_tz_offset), (0, 0))
718+
self.assertEqual((commit.committed_date, commit.committer_tz_offset), (0, 0))
719+
tag = TagObject(repo, bytes.fromhex(tag_oid))
720+
self.assertEqual((tag.tagged_date, tag.tagger_tz_offset), (0, 0))
721+
if _backend.name == "gix":
722+
for kind in ("commit", "tag"):
723+
key = (kind + ".decode", "CLI: negative signature timestamp (GIX-42)")
724+
self.assertEqual(_backend.statistics().get(key, 0), before.get(key, 0) + 1)
725+
709726
def test_deserialization_short_offset_matches_git(self):
710727
with fixture_repo("commit.sh", "short-offset") as repo:
711728
oid = (Path(repo.working_dir).parent / "object-id").read_text().strip()

‎tests/fixtures/commit.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ case "$1" in
5757
raw)
5858
git hash-object --literally -w -t commit "$2" > ../object-id
5959
;;
60-
trailing-date|zero-offset|short-offset)
60+
trailing-date|zero-offset|short-offset|negative-date)
6161
date='1112591163 +0200 1700000000 -0500'
6262
if [ "$1" = zero-offset ]; then date='1112591163 -0000'; fi
6363
if [ "$1" = short-offset ]; then date='1112591163 +020'; fi
64+
if [ "$1" = negative-date ]; then date='-1 +0200 1700000000 -0500'; fi
6465
tree=$(git mktree </dev/null)
6566
{
6667
printf 'tree %s\n' "$tree"

0 commit comments

Comments
 (0)