Skip to content

Commit 4273c5c

Browse files
committed
frmae for dir walking and handling of untracked files.
1 parent 734945a commit 4273c5c

File tree

10 files changed

+491
-27
lines changed

10 files changed

+491
-27
lines changed

Cargo.lock

Lines changed: 34 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gix-dir/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ rust-version = "1.65"
1212
doctest = false
1313

1414
[dependencies]
15+
gix-index = { version = "^0.28.1", path = "../gix-index" }
16+
gix-path = { version = "^0.10.3", path = "../gix-path" }
17+
18+
bstr = { version = "1.5.0", default-features = false }
19+
thiserror = "1.0.56"
20+
21+
[dev-dependencies]
22+
gix-testtools = { path = "../tests/tools" }

gix-dir/src/entry.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use crate::{Entry, EntryRef};
2+
3+
/// The git-style filesystem mode.
4+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
5+
pub enum Mode {
6+
/// The entry is a blob, executable or not.
7+
Blob,
8+
/// The entry is a symlink.
9+
Symlink,
10+
/// The entry is an ordinary directory, which is either untracked or ignored along with all its contents.
11+
Directory,
12+
/// The entry is a directory which contains a `.git` folder.
13+
///
14+
/// Note that we don't know if it's a submodule as we don't have `.gitmodules` information.
15+
Repository,
16+
}
17+
18+
/// The kind of entry as obtained from a directory.
19+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
20+
pub enum Kind {
21+
/// The entry is not tracked by git yet, it was not found in the [index](gix_index::State).
22+
Untracked,
23+
}
24+
25+
impl EntryRef<'_> {
26+
/// Strip the lifetime to obtain a fully owned copy.
27+
pub fn to_owned(&self) -> Entry {
28+
Entry {
29+
path: self.path.to_owned(),
30+
kind: self.kind,
31+
mode: self.mode,
32+
}
33+
}
34+
}
35+
36+
impl Entry {
37+
/// Obtain an [`EntryRef`] from this instance.
38+
pub fn to_ref(&self) -> EntryRef<'_> {
39+
EntryRef {
40+
path: &self.path,
41+
kind: self.kind,
42+
mode: self.mode,
43+
}
44+
}
45+
}

gix-dir/src/lib.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
11
//! A crate for handling a git-style directory walk.
22
#![deny(rust_2018_idioms)]
33
#![forbid(unsafe_code)]
4+
use std::path::{Path, PathBuf};
5+
6+
/// A directory entry, typically obtained using [`walk()`].
7+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
8+
pub struct EntryRef<'a> {
9+
/// The path at which the file or directory could be found, always with `root` as prefix,
10+
/// the first parameter of [`walk()`].
11+
pub path: &'a Path,
12+
/// The kind of entry.
13+
pub kind: entry::Kind,
14+
/// Further specify the what the entry is, similar to a file mode.
15+
pub mode: entry::Mode,
16+
}
17+
18+
/// Just like [`EntryRef`], but with all fields owned (and thus without a lifetime to consider).
19+
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
20+
pub struct Entry {
21+
/// The path at which the file or directory could be found, always with `root` as prefix,
22+
/// the first parameter of [`walk()`].
23+
pub path: PathBuf,
24+
/// The kind of entry.
25+
pub kind: entry::Kind,
26+
/// Further specify the what the entry is, similar to a file mode.
27+
pub mode: entry::Mode,
28+
}
29+
30+
///
31+
pub mod entry;
32+
33+
///
34+
pub mod walk;
35+
pub use walk::function::walk;

0 commit comments

Comments
 (0)