Skip to content

Commit f71396e

Browse files
committed
frmae for dir walking and handling of untracked files.
1 parent 3edf0fe commit f71396e

File tree

10 files changed

+779
-27
lines changed

10 files changed

+779
-27
lines changed

Cargo.lock

Lines changed: 35 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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ rust-version = "1.65"
1212
doctest = false
1313

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

gix-dir/src/entry.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 provided pathspec prevented further processing as the path didn't match, or it is a `.git` directory.
22+
/// 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`).
23+
Excluded,
24+
/// The entry is not tracked by git yet, it was not found in the [index](gix_index::State).
25+
Untracked,
26+
/// The entry is tracked in git.
27+
Tracked,
28+
}
29+
30+
impl EntryRef<'_> {
31+
/// Strip the lifetime to obtain a fully owned copy.
32+
pub fn to_owned(&self) -> Entry {
33+
Entry {
34+
rela_path: self.rela_path.to_owned(),
35+
kind: self.kind,
36+
mode: self.mode,
37+
}
38+
}
39+
}
40+
41+
impl Entry {
42+
/// Obtain an [`EntryRef`] from this instance.
43+
pub fn to_ref(&self) -> EntryRef<'_> {
44+
EntryRef {
45+
rela_path: self.rela_path.as_ref(),
46+
kind: self.kind,
47+
mode: self.mode,
48+
}
49+
}
50+
}

gix-dir/src/lib.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
11
//! A crate for handling a git-style directory walk.
22
#![deny(rust_2018_idioms)]
33
#![forbid(unsafe_code)]
4+
use bstr::{BStr, BString};
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 repository-relative path at which the file or directory could be found, with unix-style component separators.
10+
///
11+
/// To obtain the respective file, join it with the `worktree_root` passed to [`walk()`].
12+
/// The rationale here is that this is a compressed and normalized version compared to the paths we would otherwise get,
13+
/// which is preferable especially when converted to [`Entry`] due to lower memory requirements.
14+
///
15+
/// This also means that the original path to be presented to the user needs to be computed separately.
16+
pub rela_path: &'a BStr,
17+
/// The kind of entry.
18+
pub kind: entry::Kind,
19+
/// Further specify the what the entry is, similar to a file mode.
20+
pub mode: entry::Mode,
21+
}
22+
23+
/// Just like [`EntryRef`], but with all fields owned (and thus without a lifetime to consider).
24+
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
25+
pub struct Entry {
26+
/// The path at which the file or directory could be found, always with `root` as prefix,
27+
/// the first parameter of [`walk()`].
28+
pub rela_path: BString,
29+
/// The kind of entry.
30+
pub kind: entry::Kind,
31+
/// Further specify the what the entry is, similar to a file mode.
32+
pub mode: entry::Mode,
33+
}
34+
35+
///
36+
pub mod entry;
37+
38+
///
39+
pub mod walk;
40+
pub use walk::function::walk;

0 commit comments

Comments
 (0)