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:
: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:
parent
d8e66a4652
commit
301443db7d
28 changed files with 3159 additions and 101 deletions
|
|
@ -27,7 +27,7 @@ pub const FILE_CAP: usize = 32 * 1024 * 1024;
|
|||
pub(crate) const SMALL_CAP: usize = 16 * 1024 * 1024;
|
||||
|
||||
/// How many leading bytes [`Repo::show`] checks for NUL, as git does.
|
||||
const BINARY_PROBE: usize = 8000;
|
||||
pub(crate) const BINARY_PROBE: usize = 8000;
|
||||
|
||||
/// The installed git, checked to be recent enough.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
|
@ -167,6 +167,19 @@ pub struct Contents {
|
|||
pub too_large: bool,
|
||||
}
|
||||
|
||||
/// An object read by [`Repo::read_object`].
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) enum Object {
|
||||
/// It does not exist (or is a tree).
|
||||
Missing,
|
||||
/// It is not a blob (a submodule).
|
||||
NotBlob,
|
||||
/// It is larger than [`FILE_CAP`].
|
||||
TooLarge,
|
||||
/// The blob's bytes as stored.
|
||||
Blob(Vec<u8>),
|
||||
}
|
||||
|
||||
/// A branch.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Branch {
|
||||
|
|
@ -366,7 +379,7 @@ impl Repo {
|
|||
}
|
||||
|
||||
/// Whether HEAD points to a commit (false before the first commit).
|
||||
fn has_head(&self) -> Result<bool, VcsError> {
|
||||
pub(crate) fn has_head(&self) -> Result<bool, VcsError> {
|
||||
let output = self.run(Call::read(
|
||||
&self.root,
|
||||
&["rev-parse", "--verify", "--quiet", "HEAD^{commit}"],
|
||||
|
|
@ -483,42 +496,61 @@ impl Repo {
|
|||
pub fn show(&self, path: &str, rev: Rev) -> Result<Contents, VcsError> {
|
||||
let path = self.to_repo_path(path)?;
|
||||
let object = match rev {
|
||||
Rev::Head => format!("HEAD:{path}\n"),
|
||||
Rev::Index => format!(":0:{path}\n"),
|
||||
Rev::Head => format!("HEAD:{path}"),
|
||||
Rev::Index => format!(":0:{path}"),
|
||||
};
|
||||
Ok(match self.read_object(&object)? {
|
||||
Object::Missing => Contents::default(),
|
||||
Object::NotBlob => Contents {
|
||||
binary: true,
|
||||
..Contents::default()
|
||||
},
|
||||
Object::TooLarge => Contents {
|
||||
too_large: true,
|
||||
..Contents::default()
|
||||
},
|
||||
Object::Blob(bytes) => decode(bytes),
|
||||
})
|
||||
}
|
||||
|
||||
/// Reads an object such as `HEAD:<path>` or `:0:<path>` (a root-relative
|
||||
/// path) as stored.
|
||||
///
|
||||
/// # Errors
|
||||
/// The runner's errors or [`VcsError::BadOutput`].
|
||||
pub(crate) fn read_object(&self, object: &str) -> Result<Object, VcsError> {
|
||||
let output = self
|
||||
.run(
|
||||
Call::read(&self.root, &["cat-file", "--batch-check"], SMALL_CAP)
|
||||
.stdin(object.into_bytes()),
|
||||
Call::read(&self.root, &["cat-file", "--batch-check"], SMALL_CAP).stdin(
|
||||
format!(
|
||||
"{object}
|
||||
"
|
||||
)
|
||||
.into_bytes(),
|
||||
),
|
||||
)?
|
||||
.checked()?;
|
||||
let line = String::from_utf8_lossy(&output.stdout);
|
||||
let fields: Vec<&str> = line.trim_end().rsplitn(3, ' ').collect();
|
||||
let [size, kind, oid] = fields.as_slice() else {
|
||||
return Ok(Contents::default());
|
||||
return Ok(Object::Missing);
|
||||
};
|
||||
if *size == "missing" || *kind == "missing" || *kind == "tree" {
|
||||
return Ok(Contents::default());
|
||||
return Ok(Object::Missing);
|
||||
}
|
||||
if *kind != "blob" {
|
||||
return Ok(Contents {
|
||||
binary: true,
|
||||
..Contents::default()
|
||||
});
|
||||
return Ok(Object::NotBlob);
|
||||
}
|
||||
let size: usize = size
|
||||
.parse()
|
||||
.map_err(|_| VcsError::BadOutput(line.to_string()))?;
|
||||
if size > FILE_CAP {
|
||||
return Ok(Contents {
|
||||
too_large: true,
|
||||
..Contents::default()
|
||||
});
|
||||
return Ok(Object::TooLarge);
|
||||
}
|
||||
let output = self
|
||||
.run(Call::read(&self.root, &["cat-file", "blob", oid], FILE_CAP))?
|
||||
.checked()?;
|
||||
Ok(decode(output.stdout))
|
||||
Ok(Object::Blob(output.stdout))
|
||||
}
|
||||
|
||||
/// Local and remote-tracking branches.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue