Skip to content

Commit

Permalink
frmae for dir walking and handling of untracked files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jan 17, 2024
1 parent da3e7d7 commit 169b320
Show file tree
Hide file tree
Showing 10 changed files with 491 additions and 27 deletions.
61 changes: 34 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions gix-dir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ rust-version = "1.65"
doctest = false

[dependencies]
gix-index = { version = "^0.28.1", path = "../gix-index" }
gix-path = { version = "^0.10.3", path = "../gix-path" }

bstr = { version = "1.5.0", default-features = false }
thiserror = "1.0.56"

[dev-dependencies]
gix-testtools = { path = "../tests/tools" }
45 changes: 45 additions & 0 deletions gix-dir/src/entry.rs
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,
}
}
}
32 changes: 32 additions & 0 deletions gix-dir/src/lib.rs
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;
Loading

0 comments on commit 169b320

Please sign in to comment.