Skip to content

Commit 356903d

Browse files
committed
create new gix-fs crate to consolidate all filesystem utilities
1 parent 055611c commit 356903d

File tree

57 files changed

+242
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+242
-206
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ members = [
178178
"gix-refspec",
179179
"gix-path",
180180
"gix-utils",
181+
"gix-fs",
181182
"gix",
182183
"gitoxide-core",
183184
"gix-hashtable",

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ is usable to some extent.
8686
* `gitoxide-core`
8787
* **very early** _(possibly without any documentation and many rough edges)_
8888
* [gix-utils](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-utils)
89+
* [gix-fs](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-fs)
8990
* [gix-worktree](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-worktree)
9091
* [gix-bitmap](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-bitmap)
9192
* [gix-date](https://github.com/Byron/gitoxide/blob/main/crate-status.md#gix-date)

crate-status.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,15 @@ and itself relies on all `git-*` crates. It's not meant for consumption, for app
105105
* [x] hashset
106106

107107
### gix-utils
108-
109108
* **filesystem**
110109
* [x] probe capabilities
111110
* [x] symlink creation and removal
112111
* [x] file snapshots
112+
113+
### gix-fs
114+
* [x] probe capabilities
115+
* [x] symlink creation and removal
116+
* [x] file snapshots
113117

114118
### gix-object
115119
* *decode (zero-copy)* borrowed objects

etc/check-package-size.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ function indent () {
1717
echo "in root: gitoxide CLI"
1818
(enter cargo-smart-release && indent cargo diet -n --package-size-limit 110KB)
1919
(enter gix-actor && indent cargo diet -n --package-size-limit 5KB)
20+
(enter gix-archive && indent cargo diet -n --package-size-limit 10KB)
21+
(enter gix-utils && indent cargo diet -n --package-size-limit 10KB)
22+
(enter gix-fs && indent cargo diet -n --package-size-limit 10KB)
2023
(enter gix-pathspec && indent cargo diet -n --package-size-limit 30KB)
2124
(enter gix-refspec && indent cargo diet -n --package-size-limit 30KB)
2225
(enter gix-path && indent cargo diet -n --package-size-limit 25KB)

gitoxide-core/src/index/checkout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn checkout_exclusive(
5656
}
5757

5858
let opts = gix::worktree::index::checkout::Options {
59-
fs: gix::utils::FilesystemCapabilities::probe(dest_directory),
59+
fs: gix::fs::Capabilities::probe(dest_directory),
6060

6161
destination_is_initially_empty: true,
6262
overwrite_existing: false,

gix-attributes/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ document-features = { version = "0.2.1", optional = true }
3333

3434
[dev-dependencies]
3535
gix-testtools = { path = "../tests/tools"}
36-
gix-utils = { path = "../gix-utils" }
36+
gix-fs = { path = "../gix-fs" }
3737

3838
[package.metadata.docs.rs]
3939
all-features = true

gix-attributes/tests/search/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use bstr::{BStr, ByteSlice};
22
use gix_attributes::search::{AttributeId, Outcome};
33
use gix_attributes::{AssignmentRef, NameRef, StateRef};
44
use gix_glob::pattern::Case;
5-
use gix_utils::FilesystemCapabilities;
5+
66
use std::collections::BTreeMap;
77

88
mod specials {
@@ -62,7 +62,7 @@ fn baseline() -> crate::Result {
6262
let mut buf = Vec::new();
6363
// Due to the way our setup differs from gits dynamic stack (which involves trying to read files from disk
6464
// by path) we can only test one case baseline, so we require multiple platforms (or filesystems) to run this.
65-
let case = if FilesystemCapabilities::probe("../.git").ignore_case {
65+
let case = if gix_fs::Capabilities::probe("../.git").ignore_case {
6666
Case::Fold
6767
} else {
6868
Case::Sensitive

gix-fs/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "gix-fs"
3+
version = "0.1.0"
4+
repository = "https://github.com/Byron/gitoxide"
5+
license = "MIT/Apache-2.0"
6+
description = "A crate providing file system specific utilities to `gitoxide`"
7+
authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
8+
edition = "2021"
9+
rust-version = "1.64"
10+
11+
[lib]
12+
doctest = false
13+
14+
[dependencies]
15+
gix-features = { path = "../gix-features" }
16+
17+
[dev-dependencies]
18+
tempfile = "3.5.0"

gix-utils/src/fs_capabilities.rs renamed to gix-fs/src/capabilities.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// TODO: tests
2-
use crate::FilesystemCapabilities;
2+
use crate::Capabilities;
33
use std::path::Path;
44

55
#[cfg(windows)]
6-
impl Default for FilesystemCapabilities {
6+
impl Default for Capabilities {
77
fn default() -> Self {
8-
FilesystemCapabilities {
8+
Capabilities {
99
precompose_unicode: false,
1010
ignore_case: true,
1111
executable_bit: false,
@@ -15,9 +15,9 @@ impl Default for FilesystemCapabilities {
1515
}
1616

1717
#[cfg(target_os = "macos")]
18-
impl Default for FilesystemCapabilities {
18+
impl Default for Capabilities {
1919
fn default() -> Self {
20-
FilesystemCapabilities {
20+
Capabilities {
2121
precompose_unicode: true,
2222
ignore_case: true,
2323
executable_bit: true,
@@ -27,9 +27,9 @@ impl Default for FilesystemCapabilities {
2727
}
2828

2929
#[cfg(all(unix, not(target_os = "macos")))]
30-
impl Default for FilesystemCapabilities {
30+
impl Default for Capabilities {
3131
fn default() -> Self {
32-
FilesystemCapabilities {
32+
Capabilities {
3333
precompose_unicode: false,
3434
ignore_case: false,
3535
executable_bit: true,
@@ -38,16 +38,16 @@ impl Default for FilesystemCapabilities {
3838
}
3939
}
4040

41-
impl FilesystemCapabilities {
41+
impl Capabilities {
4242
/// try to determine all values in this context by probing them in the given `git_dir`, which
4343
/// should be on the file system the git repository is located on.
4444
/// `git_dir` is a typical git repository, expected to be populated with the typical files like `config`.
4545
///
4646
/// All errors are ignored and interpreted on top of the default for the platform the binary is compiled for.
4747
pub fn probe(git_dir: impl AsRef<Path>) -> Self {
4848
let root = git_dir.as_ref();
49-
let ctx = FilesystemCapabilities::default();
50-
FilesystemCapabilities {
49+
let ctx = Capabilities::default();
50+
Capabilities {
5151
symlink: Self::probe_symlink(root).unwrap_or(ctx.symlink),
5252
ignore_case: Self::probe_ignore_case(root).unwrap_or(ctx.ignore_case),
5353
precompose_unicode: Self::probe_precompose_unicode(root).unwrap_or(ctx.precompose_unicode),

gix-tempfile/src/fs/create_dir.rs renamed to gix-fs/src/dir/create.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Default for Retries {
2828
mod error {
2929
use std::{fmt, path::Path};
3030

31-
use crate::fs::create_dir::Retries;
31+
use crate::dir::create::Retries;
3232

3333
/// The error returned by [all()][super::all()].
3434
#[allow(missing_docs)]

gix-fs/src/dir/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
///
2+
pub mod create;
3+
///
4+
pub mod remove;
File renamed without changes.

gix-fs/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! A crate with file-system specific utilities.
2+
#![deny(rust_2018_idioms)]
3+
#![forbid(unsafe_code)]
4+
5+
/// Common knowledge about the worktree that is needed across most interactions with the work tree
6+
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
7+
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
8+
pub struct Capabilities {
9+
/// If true, the filesystem will store paths as decomposed unicode, i.e. `ä` becomes `"a\u{308}"`, which means that
10+
/// we have to turn these forms back from decomposed to precomposed unicode before storing it in the index or generally
11+
/// using it. This also applies to input received from the command-line, so callers may have to be aware of this and
12+
/// perform conversions accordingly.
13+
/// If false, no conversions will be performed.
14+
pub precompose_unicode: bool,
15+
/// If true, the filesystem ignores the case of input, which makes `A` the same file as `a`.
16+
/// This is also called case-folding.
17+
pub ignore_case: bool,
18+
/// If true, we assume the executable bit is honored as part of the files mode. If false, we assume the file system
19+
/// ignores the executable bit, hence it will be reported as 'off' even though we just tried to set it to be on.
20+
pub executable_bit: bool,
21+
/// If true, the file system supports symbolic links and we should try to create them. Otherwise symbolic links will be checked
22+
/// out as files which contain the link as text.
23+
pub symlink: bool,
24+
}
25+
mod capabilities;
26+
27+
mod snapshot;
28+
pub use snapshot::{FileSnapshot, SharedFileSnapshot, SharedFileSnapshotMut};
29+
30+
///
31+
pub mod symlink;
32+
33+
///
34+
pub mod dir;
File renamed without changes.

gix-utils/src/symlink.rs renamed to gix-fs/src/symlink.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::io::ErrorKind::AlreadyExists;
12
use std::{io, path::Path};
23

34
#[cfg(not(windows))]
@@ -35,20 +36,16 @@ pub fn create(original: &Path, link: &Path) -> io::Result<()> {
3536
}
3637
}
3738

38-
pub mod error {
39-
use std::io::ErrorKind::AlreadyExists;
40-
41-
#[cfg(not(windows))]
42-
pub fn indicates_collision(err: &std::io::Error) -> bool {
43-
// TODO: use ::IsDirectory as well when stabilized instead of raw_os_error(), and ::FileSystemLoop respectively
44-
err.kind() == AlreadyExists
39+
#[cfg(not(windows))]
40+
pub fn is_collision_error(err: &std::io::Error) -> bool {
41+
// TODO: use ::IsDirectory as well when stabilized instead of raw_os_error(), and ::FileSystemLoop respectively
42+
err.kind() == AlreadyExists
4543
|| err.raw_os_error() == Some(21)
4644
|| err.raw_os_error() == Some(62) // no-follow on symlnk on mac-os
4745
|| err.raw_os_error() == Some(40) // no-follow on symlnk on ubuntu
48-
}
46+
}
4947

50-
#[cfg(windows)]
51-
pub fn indicates_collision(err: &std::io::Error) -> bool {
52-
err.kind() == AlreadyExists || err.kind() == std::io::ErrorKind::PermissionDenied
53-
}
48+
#[cfg(windows)]
49+
pub fn is_collision_error(err: &std::io::Error) -> bool {
50+
err.kind() == AlreadyExists || err.kind() == std::io::ErrorKind::PermissionDenied
5451
}

0 commit comments

Comments
 (0)