Repository navigation
Commit 494a64c
committed
fix(gix): rename empty files in native tree diffs like Git
<!-- agent: Claude -->
On the Gix backend, `Diffable.diff()` between two trees or commits builds
its result in `_backend.tree_diff()`. When the added and deleted blob IDs
pair up unambiguously, the adapter asks Gix for exact rename tracking
with `gix.Rewrites(percentage=None)`. GixPython's `Rewrites` defaults to
`track_empty=False`, the merge-style setting that never pairs empty
blobs, while `git diff -M` (and the CLI backend) defaults to
`--rename-empty` and reports an empty file moved from `a` to `b` as
`R100`.
So for a commit that only renames an empty file (an `__init__.py`, a
`.gitkeep`, a placeholder), the CLI backend returned one `R` diff with
`renamed_file` set, and the Gix backend returned an `A` diff for the new
path and a `D` diff for the old one. The same happened with `R=True`.
Code that follows renames through `rename_from`/`rename_to`, or that
treats additions and deletions differently from renames, saw a different
history depending on the backend.
The adapter now passes `track_empty=True`, which is the Gix mode that
matches Git's default for this diff. No pairing is done in Python; the
existing ambiguity guard still sends duplicate blob IDs to Git, so
several empty files added or deleted at once keep using the CLI path.
This is adapter configuration rather than a Gix bug, so no new ledger
entry is added.
Validation on Windows with CPython 3.11, Git 2.56.0 and GixPython 0.3.0
built from source:
- `test_rename_of_empty_file`, using the new `diff.sh empty-rename`
fixture, fails on the Gix backend before the change (two diffs instead
of one) and passes on both backends after it.
- A sweep of 18 tree pairs compared against the CLI backend (empty and
non-empty renames, mode changes, symlink/file and gitlink cases,
swaps, directory moves, both directions with `R=True`) differed only
in the empty-rename case before the change and matches in every case
after it; all pairs without duplicate blob IDs stayed native.
- `test/test_diff.py` passes on the CLI backend (50 passed). On the Gix
backend, `test_diff.py`, `test_gix_backend.py`,
`test_cli_process_counts.py` and `test_commit.py` give 193 passed and
2 failed; the two failures
(`test_native_repository_lifetime_and_refresh[sha1|sha256]`) fail
identically without this change because the test machine has no
global Git identity for its `git commit`.
- `ruff check`, `ruff format --check`, `shellcheck`, `mypy` and
`git diff --check` pass. The full suite was not run.
Agent-Model: claude-opus-5-51 parent 029964a commit 494a64c
3 files changed
Lines changed: 21 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
930 | 930 | | |
931 | 931 | | |
932 | 932 | | |
933 | | - | |
| 933 | + | |
934 | 934 | | |
935 | 935 | | |
936 | 936 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
624 | 624 | | |
625 | 625 | | |
626 | 626 | | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
627 | 639 | | |
628 | 640 | | |
629 | 641 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
84 | 92 | | |
85 | 93 | | |
86 | 94 | | |
| |||
0 commit comments