Compare commits
No commits in common. "0bf0b1427b920107354556ed9225cfd20979a3cc" and "d2c853c42f0b7d3e677d290b30770c70794879a1" have entirely different histories.
0bf0b1427b
...
d2c853c42f
2 changed files with 4 additions and 57 deletions
|
|
@ -174,19 +174,6 @@ struct Job {
|
||||||
repo: Option<Arc<Repo>>,
|
repo: Option<Arc<Repo>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A git call defined outside this module, run on the git thread.
|
|
||||||
///
|
|
||||||
/// **Extension pattern** for new git commands (log, blame, merge, stash):
|
|
||||||
/// the backend goes into its own `crates/vcs/src/<area>.rs` as an
|
|
||||||
/// `impl Repo` block using the crate-internal `Repo::run`, `check_name` and
|
|
||||||
/// `SMALL_CAP`; the commands go into their own `cmd/git_<area>.rs`, whose
|
|
||||||
/// `run` resolves paths with [`rel_path`] and calls
|
|
||||||
/// `start_with(state, id, mutates, Box::new(move |repo| …))`. That becomes
|
|
||||||
/// an [`Op::Custom`] and runs like the commands here: a pending outcome,
|
|
||||||
/// git and the repository detected and cached, `gitChanged` after a call
|
|
||||||
/// with `mutates`. Neither this file nor `repo.rs` needs another change.
|
|
||||||
pub(super) type RepoFn = Box<dyn Fn(&Repo) -> Result<Value, VcsError> + Send>;
|
|
||||||
|
|
||||||
/// What one command does on its thread.
|
/// What one command does on its thread.
|
||||||
enum Op {
|
enum Op {
|
||||||
/// `git.status`.
|
/// `git.status`.
|
||||||
|
|
@ -210,18 +197,6 @@ enum Op {
|
||||||
Branches,
|
Branches,
|
||||||
/// `git.checkout`.
|
/// `git.checkout`.
|
||||||
Checkout(String),
|
Checkout(String),
|
||||||
/// A command defined in another module (log, blame, merge, stash),
|
|
||||||
/// started through [`start_with`].
|
|
||||||
#[allow(
|
|
||||||
dead_code,
|
|
||||||
reason = "extension hook; constructed once the first module uses start_with"
|
|
||||||
)]
|
|
||||||
Custom {
|
|
||||||
/// Whether it changes the repository (and sends `gitChanged`).
|
|
||||||
mutates: bool,
|
|
||||||
/// The call against the repository.
|
|
||||||
run: RepoFn,
|
|
||||||
},
|
|
||||||
/// `git.createBranch`.
|
/// `git.createBranch`.
|
||||||
CreateBranch {
|
CreateBranch {
|
||||||
/// The new branch.
|
/// The new branch.
|
||||||
|
|
@ -236,9 +211,6 @@ enum Op {
|
||||||
impl Op {
|
impl Op {
|
||||||
/// Whether the call changes the repository (and sends `gitChanged`).
|
/// Whether the call changes the repository (and sends `gitChanged`).
|
||||||
fn mutates(&self) -> bool {
|
fn mutates(&self) -> bool {
|
||||||
if let Self::Custom { mutates, .. } = self {
|
|
||||||
return *mutates;
|
|
||||||
}
|
|
||||||
!matches!(
|
!matches!(
|
||||||
self,
|
self,
|
||||||
Self::Status | Self::LastMessage | Self::Show(..) | Self::Branches
|
Self::Status | Self::LastMessage | Self::Show(..) | Self::Branches
|
||||||
|
|
@ -256,30 +228,6 @@ fn engine_error(command: &str, error: VcsError) -> EngineError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs a git call defined in another module (log, blame, merge, stash)
|
|
||||||
/// exactly like the commands here: a pending outcome, git and the
|
|
||||||
/// repository detected and cached, `gitChanged` after a change.
|
|
||||||
///
|
|
||||||
/// # Parameters
|
|
||||||
/// - `command`: the command id, for errors.
|
|
||||||
/// - `mutates`: the call changes the repository.
|
|
||||||
/// - `run`: the call; its errors map like the built-in ones.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// As [`start`].
|
|
||||||
#[allow(
|
|
||||||
dead_code,
|
|
||||||
reason = "extension hook; used by the history, blame, merge and stash modules"
|
|
||||||
)]
|
|
||||||
pub(super) fn start_with(
|
|
||||||
state: &mut State,
|
|
||||||
command: &'static str,
|
|
||||||
mutates: bool,
|
|
||||||
run: RepoFn,
|
|
||||||
) -> Result<Outcome, EngineError> {
|
|
||||||
start(state, command, Op::Custom { mutates, run })
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Runs `op` on a new thread and returns the pending outcome.
|
/// Runs `op` on a new thread and returns the pending outcome.
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
|
|
@ -488,7 +436,6 @@ fn run_op(repo: &Repo, op: &Op) -> Result<Value, VcsError> {
|
||||||
Ok(json!({"current": branches.current, "local": local, "remote": remote}))
|
Ok(json!({"current": branches.current, "local": local, "remote": remote}))
|
||||||
}
|
}
|
||||||
Op::Checkout(branch) => repo.checkout(branch).map(|()| json!({})),
|
Op::Checkout(branch) => repo.checkout(branch).map(|()| json!({})),
|
||||||
Op::Custom { run, .. } => run(repo),
|
|
||||||
Op::CreateBranch {
|
Op::CreateBranch {
|
||||||
name,
|
name,
|
||||||
from,
|
from,
|
||||||
|
|
@ -629,7 +576,7 @@ pub fn pump(state: &mut State) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolves a path param to a project-relative path with `/`.
|
/// Resolves a path param to a project-relative path with `/`.
|
||||||
pub(super) fn rel_path(state: &State, command: &str, path: &str) -> Result<String, EngineError> {
|
fn rel_path(state: &State, command: &str, path: &str) -> Result<String, EngineError> {
|
||||||
Ok(path_string(&project_path(state, command, path)?))
|
Ok(path_string(&project_path(state, command, path)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ pub const STATUS_CAP: usize = 64 * 1024 * 1024;
|
||||||
pub const FILE_CAP: usize = 32 * 1024 * 1024;
|
pub const FILE_CAP: usize = 32 * 1024 * 1024;
|
||||||
|
|
||||||
/// Cap on other read output (refs, rev-parse).
|
/// Cap on other read output (refs, rev-parse).
|
||||||
pub(crate) const SMALL_CAP: usize = 16 * 1024 * 1024;
|
const SMALL_CAP: usize = 16 * 1024 * 1024;
|
||||||
|
|
||||||
/// How many leading bytes [`Repo::show`] checks for NUL, as git does.
|
/// How many leading bytes [`Repo::show`] checks for NUL, as git does.
|
||||||
const BINARY_PROBE: usize = 8000;
|
const BINARY_PROBE: usize = 8000;
|
||||||
|
|
@ -240,7 +240,7 @@ impl Repo {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs git in the work tree root.
|
/// Runs git in the work tree root.
|
||||||
pub(crate) fn run(&self, call: Call<'_>) -> Result<runner::Output, VcsError> {
|
fn run(&self, call: Call<'_>) -> Result<runner::Output, VcsError> {
|
||||||
runner::run(&self.git.executable, call)
|
runner::run(&self.git.executable, call)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -689,7 +689,7 @@ impl Repo {
|
||||||
|
|
||||||
/// Rejects branch names and revisions git could read as an option or
|
/// Rejects branch names and revisions git could read as an option or
|
||||||
/// that hold control characters.
|
/// that hold control characters.
|
||||||
pub(crate) fn check_name(name: &str) -> Result<(), VcsError> {
|
fn check_name(name: &str) -> Result<(), VcsError> {
|
||||||
if name.is_empty() || name.starts_with('-') || name.chars().any(char::is_control) {
|
if name.is_empty() || name.starts_with('-') || name.chars().any(char::is_control) {
|
||||||
return Err(VcsError::InvalidName(name.to_string()));
|
return Err(VcsError::InvalidName(name.to_string()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue