-
-
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
491 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,45 @@ | ||
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 entry is not tracked by git yet, it was not found in the [index](gix_index::State). | ||
Untracked, | ||
} | ||
|
||
impl EntryRef<'_> { | ||
/// Strip the lifetime to obtain a fully owned copy. | ||
pub fn to_owned(&self) -> Entry { | ||
Entry { | ||
path: self.path.to_owned(), | ||
kind: self.kind, | ||
mode: self.mode, | ||
} | ||
} | ||
} | ||
|
||
impl Entry { | ||
/// Obtain an [`EntryRef`] from this instance. | ||
pub fn to_ref(&self) -> EntryRef<'_> { | ||
EntryRef { | ||
path: &self.path, | ||
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,35 @@ | ||
//! A crate for handling a git-style directory walk. | ||
#![deny(rust_2018_idioms)] | ||
#![forbid(unsafe_code)] | ||
use std::path::{Path, PathBuf}; | ||
|
||
/// A directory entry, typically obtained using [`walk()`]. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)] | ||
pub struct EntryRef<'a> { | ||
/// The path at which the file or directory could be found, always with `root` as prefix, | ||
/// the first parameter of [`walk()`]. | ||
pub path: &'a Path, | ||
/// 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 path: PathBuf, | ||
/// 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.