Repository navigation
Commit 2d2570b
fix(index): don't keep the repository alive after
`IndexFile._iter_expand_paths()` passes `os.walk()` an `onerror` callback
that re-raises the error it receives. `os.walk()` fails for every file path,
so each `index.add()` of a file raised through `raise_exc()` while its frame
local `e` still referenced the exception. That forms the cycle
exception -> `__traceback__` -> `raise_exc` frame -> exception, and the
traceback also retains the `_iter_expand_paths` generator frame, whose `self`
references the `IndexFile` and its `Repo`.
A `Repo` used to stage a file was therefore only released by the cyclic garbage
collector instead of by reference counting. Until then its persistent
`git cat-file` processes stayed alive and held repository files open, which on
Windows prevents deleting the repository. `Repo.close()` hid this by forcing
`gc.collect()`.
Delete the local in a `finally` block before the exception propagates, which
breaks the cycle without changing which errors are raised or handled.
The new test stages a file with the garbage collector disabled and checks that
dropping the `Repo` frees it. It fails before this change and passes after it
with both the CLI and Gix backends on Windows (Python 3.14).
Agent-Model: unknown
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>IndexFile.add()
1 parent 57a7865 commit 2d2570b
2 files changed
Lines changed: 23 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
464 | 464 | | |
465 | 465 | | |
466 | 466 | | |
467 | | - | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
468 | 473 | | |
469 | 474 | | |
470 | 475 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
55 | 72 | | |
56 | 73 | | |
57 | 74 | | |
| |||
0 commit comments