C3: chunk staging, unstaging and revert from the gutter and the diff viewer

- crates/vcs chunk.rs: chunks of a file (buffer text vs index, HEAD vs
  index), a minimal patch applied with git apply --cached, revert as a
  byte edit; token refusal when buffer, index or HEAD changed; CRLF
  (autocrlf and stored), no final newline, BOM, staged renames, first
  commit; binary and untracked refused. Real-git tests + property test.
- engine: git.chunks, git.stageChunk, git.unstageChunk, git.revertChunk
  (revert edits the buffer under the lock, undoable in the editor);
  cmd::git::start_then; git.lineChanges shares the vcs line diff.
- UI: chunk popup on a gutter marker click (Stage / Unstage / Revert /
  Previous / Next), hollow staged markers, vcs.showChunk, diff viewer
  hint, "partly staged" badge in the Changes window.
- Docs: G8 row, Git parity row evidence, ui-parity, architecture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-11-01 12:50:11 +01:00
parent d8e66a4652
commit 301443db7d
28 changed files with 3159 additions and 101 deletions

View file

@ -187,6 +187,11 @@ struct Job {
/// with `mutates`. Neither this file nor `repo.rs` needs another change.
pub(super) type RepoFn = Box<dyn Fn(&Repo) -> Result<Value, VcsError> + Send>;
/// A step run under the lock after a [`start_then`] call succeeded: it
/// takes the call's value and returns the command's (chunk revert edits
/// the editor buffer here).
pub(super) type ThenFn = Box<dyn FnOnce(&mut State, Value) -> Result<Value, EngineError> + Send>;
/// What one command does on its thread.
enum Op {
/// `git.status`.
@ -277,7 +282,22 @@ pub(super) fn start_with(
mutates: bool,
run: RepoFn,
) -> Result<Outcome, EngineError> {
start(state, command, Op::Custom { mutates, run })
start(state, command, Op::Custom { mutates, run }, None)
}
/// As [`start_with`], then runs `then` under the lock with the call's value
/// once it succeeded.
///
/// # Errors
/// As [`start`]; the outcome fails with `then`'s error.
pub(super) fn start_then(
state: &mut State,
command: &'static str,
mutates: bool,
run: RepoFn,
then: ThenFn,
) -> Result<Outcome, EngineError> {
start(state, command, Op::Custom { mutates, run }, Some(then))
}
/// Runs `op` on a new thread and returns the pending outcome.
@ -285,7 +305,12 @@ pub(super) fn start_with(
/// # Errors
/// [`EngineError::Disabled`] without a project, [`EngineError::Failed`]
/// when [`MAX_RUNNING`] calls are running already.
fn start(state: &mut State, command: &'static str, op: Op) -> Result<Outcome, EngineError> {
fn start(
state: &mut State,
command: &'static str,
op: Op,
then: Option<ThenFn>,
) -> Result<Outcome, EngineError> {
let project = state
.project
.as_ref()
@ -349,7 +374,11 @@ fn start(state: &mut State, command: &'static str, op: Op) -> Result<Outcome, En
.unwrap_or_else(PoisonError::into_inner)
.take()
.ok_or_else(|| EngineError::Failed("git did not answer in time".into()))?;
finish(state, &project, reply)
let value = finish(state, &project, reply)?;
match then {
Some(then) => then(state, value),
None => Ok(value),
}
})))
}
@ -674,7 +703,7 @@ impl Command for StatusCommand {
fn run(&self, state: &mut State, params: Value) -> Result<Outcome, EngineError> {
let command = self.spec().id;
let _: serde_json::Map<String, Value> = parse(command, params)?;
start(state, command, Op::Status)
start(state, command, Op::Status, None)
}
}
@ -699,7 +728,7 @@ impl Command for Stage {
fn run(&self, state: &mut State, params: Value) -> Result<Outcome, EngineError> {
let command = self.spec().id;
let paths = paths(state, command, params)?;
start(state, command, Op::Stage(paths))
start(state, command, Op::Stage(paths), None)
}
}
@ -724,7 +753,7 @@ impl Command for Unstage {
fn run(&self, state: &mut State, params: Value) -> Result<Outcome, EngineError> {
let command = self.spec().id;
let paths = paths(state, command, params)?;
start(state, command, Op::Unstage(paths))
start(state, command, Op::Unstage(paths), None)
}
}
@ -770,6 +799,7 @@ impl Command for Commit {
message: p.message,
amend: p.amend,
},
None,
)
}
}
@ -795,7 +825,7 @@ impl Command for LastMessage {
fn run(&self, state: &mut State, params: Value) -> Result<Outcome, EngineError> {
let command = self.spec().id;
let _: serde_json::Map<String, Value> = parse(command, params)?;
start(state, command, Op::LastMessage)
start(state, command, Op::LastMessage, None)
}
}
@ -847,7 +877,7 @@ impl Command for Show {
RefParam::Head => Rev::Head,
RefParam::Index => Rev::Index,
};
start(state, command, Op::Show(path, rev))
start(state, command, Op::Show(path, rev), None)
}
}
@ -872,7 +902,7 @@ impl Command for BranchesCommand {
fn run(&self, state: &mut State, params: Value) -> Result<Outcome, EngineError> {
let command = self.spec().id;
let _: serde_json::Map<String, Value> = parse(command, params)?;
start(state, command, Op::Branches)
start(state, command, Op::Branches, None)
}
}
@ -905,7 +935,7 @@ impl Command for Checkout {
fn run(&self, state: &mut State, params: Value) -> Result<Outcome, EngineError> {
let command = self.spec().id;
let p: CheckoutParams = parse(command, params)?;
start(state, command, Op::Checkout(p.branch))
start(state, command, Op::Checkout(p.branch), None)
}
}
@ -951,6 +981,7 @@ impl Command for CreateBranch {
from: p.from,
checkout: p.checkout,
},
None,
)
}
}