-
-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frmae for dir walking and handling of untracked files.
- Loading branch information
Showing
10 changed files
with
783 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::{Entry, EntryRef}; | ||
|
||
/// The git-style filesystem mode. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)] | ||
pub enum Mode { | ||
/// The entry is a blob, executable or not. | ||
Blob, | ||
/// The entry is a symlink. | ||
Symlink, | ||
/// The entry is an ordinary directory, which is either untracked or ignored along with all its contents. | ||
Directory, | ||
/// The entry is a directory which *contains* a `.git` folder. | ||
/// | ||
/// Note that we don't know if it's a submodule as we don't have `.gitmodules` information. | ||
Repository, | ||
} | ||
|
||
/// The kind of entry as obtained from a directory. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)] | ||
pub enum Kind { | ||
/// The provided pathspec prevented further processing as the path didn't match, or it is a `.git` directory. | ||
/// If this happens, no further checks are done so we wouldn't know if the path is also ignored for example (by mention in `.gitignore`). | ||
Excluded, | ||
/// The entry is not tracked by git yet, it was not found in the [index](gix_index::State). | ||
Untracked, | ||
/// The entry is tracked in git. | ||
Tracked, | ||
} | ||
|
||
impl EntryRef<'_> { | ||
/// Strip the lifetime to obtain a fully owned copy. | ||
pub fn to_owned(&self) -> Entry { | ||
Entry { | ||
rela_path: self.rela_path.to_owned(), | ||
kind: self.kind, | ||
mode: self.mode, | ||
} | ||
} | ||
} | ||
|
||
impl Entry { | ||
/// Obtain an [`EntryRef`] from this instance. | ||
pub fn to_ref(&self) -> EntryRef<'_> { | ||
EntryRef { | ||
rela_path: self.rela_path.as_ref(), | ||
kind: self.kind, | ||
mode: self.mode, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,40 @@ | ||
//! A crate for handling a git-style directory walk. | ||
#![deny(rust_2018_idioms)] | ||
#![forbid(unsafe_code)] | ||
use bstr::{BStr, BString}; | ||
|
||
/// A directory entry, typically obtained using [`walk()`]. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)] | ||
pub struct EntryRef<'a> { | ||
/// The repository-relative path at which the file or directory could be found, with unix-style component separators. | ||
/// | ||
/// To obtain the respective file, join it with the `worktree_root` passed to [`walk()`]. | ||
/// The rationale here is that this is a compressed and normalized version compared to the paths we would otherwise get, | ||
/// which is preferable especially when converted to [`Entry`] due to lower memory requirements. | ||
/// | ||
/// This also means that the original path to be presented to the user needs to be computed separately. | ||
pub rela_path: &'a BStr, | ||
/// The kind of entry. | ||
pub kind: entry::Kind, | ||
/// Further specify the what the entry is, similar to a file mode. | ||
pub mode: entry::Mode, | ||
} | ||
|
||
/// Just like [`EntryRef`], but with all fields owned (and thus without a lifetime to consider). | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] | ||
pub struct Entry { | ||
/// The path at which the file or directory could be found, always with `root` as prefix, | ||
/// the first parameter of [`walk()`]. | ||
pub rela_path: BString, | ||
/// The kind of entry. | ||
pub kind: entry::Kind, | ||
/// Further specify the what the entry is, similar to a file mode. | ||
pub mode: entry::Mode, | ||
} | ||
|
||
/// | ||
pub mod entry; | ||
|
||
/// | ||
pub mod walk; | ||
pub use walk::function::walk; |
Oops, something went wrong.