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: PlanOriginImplementations§
Source§impl Plan
impl Plan
Sourcepub fn apply(&self, dirty: DirtyFiles) -> Result<(), FilesError>
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.
Sourcepub fn stage(&self) -> Result<(), FilesError>
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
impl Plan
Sourcepub fn operations(&self) -> &[Operation]
pub fn operations(&self) -> &[Operation]
Return the operations this plan will execute.
Sourcepub fn dirty_paths(&self) -> &[RepositoryPath]
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.
Sourcepub fn is_dirty(&self, operation: &Operation) -> bool
pub fn is_dirty(&self, operation: &Operation) -> bool
Whether operation touches a path in Plan::dirty_paths.
Sourcepub fn foreign_paths(&self) -> &[RepositoryPath]
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.
Sourcepub fn current_content(
&self,
path: &RepositoryPath,
) -> Result<Option<Vec<u8>>, FilesError>
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.
Sourcepub fn for_repository(
root: &RepositoryRoot,
state: &FileState,
) -> Result<Self, FilesError>
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.
Sourcepub fn for_expected_updates(
root: &RepositoryRoot,
entries: &[(RepositoryPath, Option<Vec<u8>>, Option<Vec<u8>>)],
) -> Result<Self, FilesError>
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.
Sourcepub fn for_snapshot(
root: &RepositoryRoot,
state: &FileState,
) -> Result<Self, FilesError>
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§
impl Eq for Plan
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.