Skip to main content

WorktreeModePolicy

Struct WorktreeModePolicy 

Source
pub struct WorktreeModePolicy {
    pub trust_filemode: bool,
    pub has_symlinks: bool,
}
Expand description

What the worktree filesystem can express about a tracked path’s mode.

Git records these capabilities per repository as core.filemode (is the executable bit meaningful?) and core.symlinks (can the checkout hold symbolic links?). Both default to true; git init/git clone write false when probing the filesystem fails, which is the norm on Windows. When a capability is missing, the worktree cannot show that aspect of a path, so the mode already recorded in the index wins over what lstat reports.

Use WorktreeModePolicy::index_mode_for_worktree whenever a worktree mode is compared with or written over an index entry: staging, status and worktree diffs all share it.

Fields§

§trust_filemode: bool

core.filemode: the worktree’s executable bit is meaningful.

§has_symlinks: bool

core.symlinks: the worktree can hold symbolic links.

Implementations§

Source§

impl WorktreeModePolicy

Source

pub fn from_config(config: &ConfigSet) -> Self

Read core.filemode and core.symlinks from config, defaulting each to true when unset or not a boolean.

Source

pub fn index_mode_for_worktree( self, worktree_mode: u32, recorded_mode: Option<u32>, ) -> u32

The mode to record for a path given its worktree mode and the mode currently recorded.

Rules, in order:

  1. Without symlink support, a regular file standing in for a recorded symlink (MODE_SYMLINK) stays a symlink: the file holds the link target.
  2. Without a trusted executable bit, a regular file over a recorded regular file keeps the recorded 100644/100755.
  3. Otherwise the worktree mode wins (including real type changes such as a directory, a symlink on a symlink-capable checkout, or a gitlink).
§Parameters
  • worktree_mode — Git mode derived from lstat (see crate::diff::mode_from_metadata).
  • recorded_mode — the index entry’s mode, or None for a path not yet tracked (the worktree mode is then returned unchanged).
§Returns

The Git mode to compare against or store in the index.

Source

pub fn worktree_mode_matches( self, worktree_mode: u32, recorded_mode: u32, ) -> bool

Whether a worktree mode is indistinguishable from recorded_mode under this policy.

Equivalent to index_mode_for_worktree(worktree_mode, Some(recorded_mode)) == recorded_mode.

Trait Implementations§

Source§

impl Clone for WorktreeModePolicy

Source§

fn clone(&self) -> Self

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 Copy for WorktreeModePolicy

Source§

impl Debug for WorktreeModePolicy

Source§

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

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

impl Default for WorktreeModePolicy

Source§

fn default() -> Self

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

impl Eq for WorktreeModePolicy

Source§

impl PartialEq for WorktreeModePolicy

Source§

fn eq(&self, other: &Self) -> 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 WorktreeModePolicy

Auto Trait Implementations§

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
Source§

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

Source§

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

Checks if this value is equivalent to the given key. 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> Same for T

Source§

type Output = T

Should always be Self
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, !>

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.