Repository navigation
fix(discard): discard staged changes under one index lock - #91
Conversation
|
this one is ready as well - but after #87 |
|
Thanks for splitting it out. I'm going to hold this one for now. The crash case is still the thing I need settled first, since a discard that dies halfway leaves the user's files in hidden folders inside their worktree, and those show up as untracked files. I'm also wary of the size: stage.rs goes from about 560 to 2,700 lines. Could the index lock be taken before any file moves, so a lock failure leaves everything untouched? That might remove most of the need for rollback. If backups are still needed, |
f69ee91 to
edeb768
Compare
655da6e to
d47c7be
Compare
|
Updated in d47c7be in response to your feedback:
Both CI runs are fully green: #91 and #87, including Linux, macOS, Windows, frontend checks and Playwright. |
8cc758b to
3418712
Compare
3418712 to
2a48d1d
Compare
|
Rebased onto This PR now contains only the discard transaction/recovery commit, Validation: |
|
Thanks for sticking with this. The crash case is settled now that backups live under .git, but the PR went the other way on size: about 3,700 lines of non-test code to replace roughly 100, with a journal, recovery, cross-device copying and Windows NT calls. I measured 2,200 staged files and it's the same speed as main, so the gain is crash safety for a rare case, and I can't maintain that much machinery for it. What I had in mind was smaller. Take index.lock, run the existing per-file restore against the in-memory index, write the index once, and report any file that fails through DiscardBatch like #87 already does. No journal and no recovery on open. Also, recovery runs on every tab switch, so a backup it can't recover shows the warning toast every time you switch, with a raw serde message. Even with recovery in, that would need to warn once and offer a way to clear it. If the smaller version doesn't feel worth it to you, that's completely fine, just tell me and I'll close this. The batch reporting from #87 already covers the main problem, and I really appreciate all the work you've put into the hooks series. |
Take .git/index.lock before touching any file, run the per-file restore against a private copy of the index and write it once. A file that fails stays as it was and is reported through DiscardBatch. Paths are matched literally, so a name like [ab].txt no longer resets a.txt, and either name of a staged rename restores the original. No journal, no recovery on open.
2a48d1d to
137d2ad
Compare
|
Thanks, that's fair. I've force-pushed the smaller version: take Two fixes came along because they fit naturally. Paths are matched literally now: on main, discarding |
cheat2001
left a comment
There was a problem hiding this comment.
Thanks, this is exactly what I had in mind. I checked it against main here: discarding 2,200 staged files went from about 10.5 s to 5 s, and I could reproduce the [ab].txt bug on main, so good catch on that one. One wording nit in the changelog, it doesn't wait for the lock, it stops when another process holds it. I'll fix that when I merge.
What & why
Take
.git/index.lockbefore touching any file, run the per-file restore against a private copy of the index and write it once. A file that fails stays as it was and is reported throughDiscardBatch. If another process holds the lock, nothing is discarded and the error names the lock file.Paths are matched literally, so discarding
[ab].txtno longer resetsa.txt(the file name used to go to checkout as a pattern), and picking either name of a staged rename restores the original. No journal, no recovery on open.Tests
New engine tests in
tests/git_engine.rs:index.lockchanges nothing, and the retry after it is gone discards and leaves no lock behindThe first three fail against main's code.
cargo fmt --check,cargo clippy --all-targets -D warningsand the full Rust suite pass on macOS.