Struct determinator::Paths0 [−][src]
A store for null-separated paths.
This manages paths on Unix and Windows platforms, including converting /
on Windows to \
.
Null-separated paths
Paths as produced by tools like git diff --name-only
are typically separated by newline
characters (\n
). However, on Unix platforms filenames can themselves have newlines embedded in
them, so source control systems often end up
quoting newlines and other "unusual" characters.
A robust, lossless way to retrieve a list of paths is by separating them with null characters. Both Unix and Windows platforms guarantee that a path can never have embedded null characters.
Examples
Most source control systems can provide null-separated paths. These examples are expected to be run from the Cargo workspace root (which is assumed to be the same as the repository root).
In most cases, you'll want to compare the current working directory against the merge base,
or nearest/greatest/lowest common ancestor,
of the current commit with a specified upstream revision, such as origin/main
. To do so,
run:
- Git:
git diff -z --name-only $(git merge-base <upstream rev> HEAD)
- Mercurial:
hg status --print0 -mard --no-status --rev 'ancestor(<upstream rev>,.)'
NOTE:
- The
$()
syntax in Bash and other shells means "run the command and insert its contents here". - Git provides a syntax
<upstream rev>...
which purports to use the merge base, but it ignores uncommitted changes. Executinggit merge-base
as a separate command is the only way to include uncommitted changes. - The
-mard
flag tohg status
means that untracked files are not included.git diff
does not have an option to display untracked files. For more discussion, see the documentation foradd_changed_paths
.
In general, to obtain a list of changed paths between two revisions (omit <new rev>
if comparing against the working directory):
- Git:
git diff -z --name-only <old rev> <new rev>
- Mercurial:
hg status --print0 -mard --no-status <old rev> <new rev>
To obtain a list of all files in the working directory that are tracked by the source control system:
- Git:
git ls-files -z
- Mercurial:
hg files --print0
Null-separated paths are produced through the -z
option to Git commands, or the --print0
option to Mercurial. If you're using a different system, check its help for instructions.
Implementations
&'a Paths0
implements IntoIterator<Item = &'a Path>
.
Implementations
impl Paths0
[src]
pub fn new(buf: impl Into<Vec<u8>>) -> Result<Self, (Vec<u8>, Utf8Error)>
[src]
Creates a new instance of Paths0
from a buffer.
The buffer may, but does not need to, have a trailing byte.
Errors
On Unixes this supports arbitrary paths and is infallible.
On other platforms like Windows, this only supports paths encoded as UTF-8. Any others will return an error containing:
- the first path that failed to parse
- the
Utf8Error
that it returned.
pub fn new_forward_slashes(
buf: impl Into<Vec<u8>>
) -> Result<Self, (Vec<u8>, Utf8Error)>
[src]
buf: impl Into<Vec<u8>>
) -> Result<Self, (Vec<u8>, Utf8Error)>
Creates a new instance of Paths0
, converting /
to \
on platforms like Windows.
Some tools like Git (but not Mercurial) return paths with /
on Windows, even though the
canonical separator on the platform is \
. This constructor changes all instances of /
to \
.
pub fn new_unix(buf: impl Into<Vec<u8>>) -> Self
[src]
Creates a new instance of Paths0
on Unix platforms.
This is infallible, but is only available on Unix platforms.
pub fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = &'a Path> + 'a>
[src]
Iterates over the paths in this buffer.
Trait Implementations
impl Clone for Paths0
[src]
impl Debug for Paths0
[src]
impl Eq for Paths0
[src]
impl<'a> IntoIterator for &'a Paths0
[src]
type Item = &'a Path
The type of the elements being iterated over.
type IntoIter = Box<dyn Iterator<Item = &'a Path> + 'a>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl Ord for Paths0
[src]
fn cmp(&self, other: &Paths0) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Paths0> for Paths0
[src]
impl PartialOrd<Paths0> for Paths0
[src]
fn partial_cmp(&self, other: &Paths0) -> Option<Ordering>
[src]
fn lt(&self, other: &Paths0) -> bool
[src]
fn le(&self, other: &Paths0) -> bool
[src]
fn gt(&self, other: &Paths0) -> bool
[src]
fn ge(&self, other: &Paths0) -> bool
[src]
impl StructuralEq for Paths0
[src]
impl StructuralPartialEq for Paths0
[src]
Auto Trait Implementations
impl RefUnwindSafe for Paths0
[src]
impl Send for Paths0
[src]
impl Sync for Paths0
[src]
impl Unpin for Paths0
[src]
impl UnwindSafe for Paths0
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<'a, T> DefaultFeatures<'a> for T where
T: 'a + Clone + Send + Sync,
T: 'a + Clone + Send + Sync,
pub fn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a> + 'a, Global>
pub fn self_address_mut(&mut self) -> *mut ()
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<'a, T> NonSyncFeatures<'a> for T where
T: 'a + Clone,
T: 'a + Clone,
pub fn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a> + 'a, Global>
pub fn self_address_mut(&mut self) -> *mut ()
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> SafeBorrow<T> for T where
T: ?Sized,
T: ?Sized,
pub fn borrow_replacement(ptr: &T) -> &T
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,