Skip to content

Commit d9c5286

Browse files
codexByron
authored andcommitted
fix(gix): resolve textual reflog dates with Git
GixPython 0.4.0 resolves `HEAD@{never}` to the oldest reflog entry, where Git 2.54 rejects the date. The two engines also select different entries for `HEAD@{2days3hours}`. Use the shared revision guard so both native resolution paths fall back to Git for textual date selectors. The reflog fixture checks an invalid and a valid textual date alongside ordinary selectors. The full revision test file passed on both backends. Agent-Model: unknown
1 parent 5ddd5f6 commit d9c5286

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎doc/gix-backend.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ identify the historical fixture where needed.
10121012
| GIX-36 | Classification fixed in Gitoxide 0.91.0; raw mode mismatch open | With Git 2.54.0 and GixPython 0.3.0, `Tree.iter()` reports tree entry modes as stored, while Git canonicalizes them when it reads a tree (`canon_mode`): `git ls-tree` and checkout use `100755` for `100700`, `120000` for `120777` and `160000` for every mode whose type is not a regular file, symbolic link or directory. `TreeEntry.mode()` returned `0o100700` and `0o120777`, so `Blob.mode` did not match `Blob.executable_mode` or `Blob.link_mode` for entries Git checks out as an executable or a symbolic link. A `140000` entry, which Git reads as a gitlink, is reported as a tree with mode `0o40000`, so GitPython listed the contents of an object Git never checks out; other noncanonical gitlink modes made tree iteration raise `TypeError`. `git fsck` reports these trees only as `badFilemode` warnings, so default transfers accept them. The `tree-modes.sh` read-only fixture reproduces all three for SHA-1 and SHA-256. | Gitoxide preserves the raw mode and fixes classification in `74a7a86060`. `_ls_tree()` formats the native kinds as Git listing modes. `test_native_tree_entry_modes_match_git` verifies the listing against Git on the GixPython 0.4.0 wheel. The raw-mode mismatch remains open. Expose Git's canonical mode as a separate native projection. |
10131013
| GIX-37 | Bug (open) | On macOS with Git 2.54.0 and GixPython 0.3.0 or 0.4.0, create a linear history `A <- B <- C` with `HEAD` at `C` and write `B`'s full SHA-1 followed by a space and newline to `.git/shallow`. `git rev-list --skip=1 HEAD` returns only `B` and stops at the shallow boundary. `Repository.rev_walk([repo.head_id()]).all()` instead raises a `gix.Error` when consumed: `gix-shallow` treats the trailing space as a 41st hexadecimal character. | Match Git's shallow-file parsing in Gitoxide. `Commit.iter_parents(first_parent=False)` keeps the existing CLI fallback in `_backend.history()` and returns `B` with or without `max_count=1`. An explicitly native `first_parent=True` walk still exposes the parsing mismatch, which also occurs through `Commit.iter_items(..., first_parent=True, skip=1)`. |
10141014
| GIX-38 | Bug (open) | With Git 2.54.0 and GixPython 0.4.0, the `commit.sh short-offset` fixture stores `1112591163 +020` in an identity. `git show -s --format=%ad --date=raw` reports `1112591163 +0020`, while `Commit.author()` reports an offset of zero. A separate probe with `+0299` preserves that spelling in Git but renders as `+0339` from the native offset in seconds. | Expose Git-compatible interpretation of short offsets and a way to preserve the stored offset spelling. `object_metadata()` accepts native dates when their formatted prefix matches the raw identity and otherwise keeps the existing CLI fallback. `test_deserialization_short_offset_matches_git` verifies the fallback returns the 20-minute offset. |
1015+
| 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. |
10151016

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

‎git/_backend.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ def _canonical_repository(repo: Any) -> Any:
168168
def _check_revision_grammar(ref: str) -> None:
169169
if ref.startswith(":/") or "^{/" in ref or "-dirty" in ref or re.search(r"-\d+-g[0-9a-fA-F]+|^[0-9a-fA-F]+-", ref):
170170
raise _Unsupported("revision grammar differences (GIX-17)")
171+
prefix, opener, remainder = ref.partition("@{")
172+
if opener and ":" not in prefix:
173+
selector, closer, _ = remainder.partition("}")
174+
if closer and not (
175+
re.fullmatch(r"[0-9]+", selector)
176+
or (not prefix and re.fullmatch(r"-[0-9]+", selector))
177+
or selector.lower() in {"u", "upstream", "p", "push"}
178+
):
179+
raise _Unsupported("textual reflog dates (GIX-39)")
171180

172181

173182
def _oid(repo: Any, ref: Any, env: Optional[Dict[str, Any]] = None) -> Any:

‎test/test_rev_parse.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pytest
1212
from gitdb.exc import BadName
1313

14-
from git import Commit, Repo, GitCommandError
14+
from git import Commit, Repo, GitCommandError, _backend
1515
from test.lib.fixtures import fixture_repo, read_only_fixture
1616

1717

@@ -154,6 +154,15 @@ def test_rev_parse_reflog_selectors(rev_parse_repo):
154154

155155
assert repo.rev_parse("%s@{upstream}" % main.name) == merge
156156

157+
before = _backend.statistics()
158+
with pytest.raises((BadName, GitCommandError)):
159+
repo.rev_parse("HEAD@{never}")
160+
revision = "HEAD@{1970-01-01 00:00:01 +0000}"
161+
assert repo.rev_parse(revision).hexsha == repo.git.rev_parse("--verify", revision)
162+
if _backend.name == "gix":
163+
key = ("rev_parse", "CLI: textual reflog dates (GIX-39)")
164+
assert _backend.statistics().get(key, 0) == before.get(key, 0) + 2
165+
157166

158167
def test_rev_parse_commit_message_search(rev_parse_repo):
159168
repo = rev_parse_repo["repo"]

0 commit comments

Comments
 (0)