Skip to main content

Plan

Struct Plan 

Source
pub struct Plan {
    operations: Vec<Operation>,
    pub(crate) preconditions: Vec<Precondition>,
    dirty: Vec<RepositoryPath>,
    foreign: Vec<RepositoryPath>,
    pub(crate) root: PathBuf,
    pub(crate) origin: PlanOrigin,
}
Expand description

The filesystem changes needed to reach a desired file state.

Fields§

§operations: Vec<Operation>§preconditions: Vec<Precondition>§dirty: Vec<RepositoryPath>§foreign: Vec<RepositoryPath>§root: PathBuf§origin: PlanOrigin

Implementations§

Source§

impl Plan

Source

pub fn apply(&self, dirty: DirtyFiles) -> Result<(), FilesError>

Apply this plan without touching the Git index.

With DirtyFiles::Refuse, a plan that touches a dirty path fails before the first write.

Every source is checked against its snapshot first, so a stale plan fails before any write. Then all operations run in order. The plan is not atomic: when an operation fails, the earlier operations stay applied and the error names the failed path.

§Errors

Returns an error when foreign files are present, a dirty path is refused, a precondition no longer holds, or a filesystem operation cannot be completed safely.

Source

pub fn stage(&self) -> Result<(), FilesError>

Stage every created or replaced file and unstage every deleted file.

Call this after Plan::apply succeeded.

§Errors

Returns an error when the repository cannot be opened or the index cannot be updated.

Source§

impl Plan

Source

pub fn operations(&self) -> &[Operation]

Return the operations this plan will execute.

Source

pub fn dirty_paths(&self) -> &[RepositoryPath]

Return the planned paths whose current state Git cannot recover.

Only plans from Plan::for_repository can have dirty paths.

Source

pub fn is_dirty(&self, operation: &Operation) -> bool

Whether operation touches a path in Plan::dirty_paths.

Source

pub fn foreign_paths(&self) -> &[RepositoryPath]

Return the tracked paths in managed paths that Ephemeris neither generates nor marked as generated. Plan::apply refuses a plan that has any.

Source

pub fn current_content( &self, path: &RepositoryPath, ) -> Result<Option<Vec<u8>>, FilesError>

Return the content a planned path holds in the tree the plan was built against, or None when the path does not exist there.

§Errors

Returns an error when the path cannot be read.

Source

pub fn for_repository( root: &RepositoryRoot, state: &FileState, ) -> Result<Self, FilesError>

Plan changes against a live Git worktree.

Paths that would overwrite unrecoverable worktree data are recorded in Plan::dirty_paths. Plan::apply decides what to do with them.

§Errors

Returns an error when the desired state is invalid, Git cannot be inspected, or a planned path is a symlink.

Source

pub fn for_expected_updates( root: &RepositoryRoot, entries: &[(RepositoryPath, Option<Vec<u8>>, Option<Vec<u8>>)], ) -> Result<Self, FilesError>

Plan a fixed set of whole-file replacements using caller-supplied expected content as preconditions, instead of reading the repository to discover what each path currently holds.

Each entry is (path, expected, replacement). expected = None means the path must not exist yet; expected = Some(bytes) means the path must currently hold exactly those bytes. replacement = None records a read-only precondition: Plan::apply checks it but writes nothing for that path. This lets a caller capture expected content once, during planning, and have Plan::apply reject the whole plan if any of it changed before the plan was applied.

§Errors

Returns an error for invalid or duplicate paths, or a path that is unexpectedly a symlink.

Source

pub fn for_snapshot( root: &RepositoryRoot, state: &FileState, ) -> Result<Self, FilesError>

Plan changes against a read-only source snapshot.

§Errors

Returns an error when the desired state or source snapshot is invalid.

Trait Implementations§

Source§

impl Clone for Plan

Source§

fn clone(&self) -> Plan

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Plan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Plan

Source§

impl PartialEq for Plan

Source§

fn eq(&self, other: &Plan) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Plan

Auto Trait Implementations§

§

impl Freeze for Plan

§

impl RefUnwindSafe for Plan

§

impl Send for Plan

§

impl Sync for Plan

§

impl Unpin for Plan

§

impl UnsafeUnpin for Plan

§

impl UnwindSafe for Plan

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, dest: *mut u8)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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 = !

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.