gix_filter::driver

Struct State

source
pub struct State {
    pub context: Context,
    /* private fields */
}
Expand description

State required to handle process filters, which are running until all their work is done.

These can be significantly faster on some platforms as they are launched only once, while supporting asynchronous processing.

§Lifecycle

Note that shutdown() must be called to finalize long-running processes. Failing to do so will naturally shut them down by terminating their pipes, but finishing explicitly allows to wait for processes as well.

Fields§

§context: Context

The context to pass to spawned filter programs.

Implementations§

source§

impl State

Lifecycle

source

pub fn maybe_launch_process( &mut self, driver: &Driver, operation: Operation, rela_path: &BStr, ) -> Result<Option<Process<'_>>, Error>

Obtain a process as defined in driver suitable for a given operation. rela_pathmay be used to substitute the current file for use in the invokedSingleFile` process.

Note that if a long-running process is defined, the operation isn’t relevant and capabilities are to be checked by the caller.

source§

impl State

Apply operations to filter programs.

source

pub fn apply<'a>( &'a mut self, driver: &Driver, src: &mut impl Read, operation: Operation, ctx: Context<'_, '_>, ) -> Result<Option<Box<dyn Read + 'a>>, Error>

Apply operation of driver to the bytes read from src and return a reader to immediately consume the output produced by the filter. rela_path is the repo-relative path of the entry to handle. It’s possible that the filter stays inactive, in which case the src isn’t consumed and has to be used by the caller.

Each call to this method will cause the corresponding filter to be invoked unless driver indicates a process filter, which is only launched once and maintained using this state.

Note that it’s not an error if there is no filter process for operation or if a long-running process doesn’t supported the desired capability.

§Deviation

If a long running process returns the ‘abort’ status after receiving the data, it will be removed similar to how git does it. However, it delivers an unsuccessful error status later, it will not be removed, but reports the error only. If any other non-‘error’ status is received, the process will be stopped. But that doesn’t happen if if such a status is received after reading the filtered result.

source

pub fn apply_delayed<'a>( &'a mut self, driver: &Driver, src: &mut impl Read, operation: Operation, delay: Delay, ctx: Context<'_, '_>, ) -> Result<Option<MaybeDelayed<'a>>, Error>

Like [apply()]Self::apply(), but use delay to determine if the filter result may be delayed or not.

Poll list_delayed_paths() until it is empty and query the available paths again. Note that even though it’s possible, the API assumes that commands aren’t mixed when delays are allowed.

source§

impl State

Lifecycle

source

pub fn shutdown( self, mode: Mode, ) -> Result<Vec<(BString, Option<ExitStatus>)>, Error>

Handle long-running processes according to mode. If an error occurs, all remaining processes will be ignored automatically. Return a list of (process, Option<status>)

source§

impl State

Operations related to delayed filtering.

source

pub fn list_delayed_paths( &mut self, process: &Key, ) -> Result<Vec<BString>, Error>

Return a list of delayed paths for process that can then be obtained with fetch_delayed().

A process abiding the protocol will eventually list all previously delayed paths for any invoked command, or signals that it is done with all delayed paths by returning an empty list. It’s up to the caller to validate these assumptions.

§Error Handling

Usually if the process sends the “abort” status, we will not use a certain capability again. Here it’s unclear what capability that is and what to do, so we leave the process running and do nothing else (just like git).

source

pub fn fetch_delayed( &mut self, process: &Key, path: &BStr, operation: Operation, ) -> Result<impl Read + '_, Error>

Given a process and a path (as previously returned by list_delayed_paths()), return a reader to stream the filtered result. Note that operation must match the original operation that produced the delayed result or the long-running process might not know the path, depending on its implementation.

source§

impl State

Initialization

source

pub fn new(context: Context) -> Self

Create a new instance using context to inform launched processes about their environment.

Trait Implementations§

source§

impl Clone for State

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for State

source§

fn default() -> State

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for State

§

impl RefUnwindSafe for State

§

impl Send for State

§

impl Sync for State

§

impl Unpin for State

§

impl UnwindSafe for State

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.