1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//! A crate with file-system specific utilities.
//!
//! ## Examples
//!
//! ```
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use std::path::{Path, PathBuf};
//!
//! use gix_fs::{
//! stack::{Delegate, ToNormalPathComponents},
//! Stack,
//! };
//!
//! let components = "src/lib.rs"
//! .to_normal_path_components()
//! .collect::<Result<Vec<_>, _>>()?;
//! assert_eq!(
//! components
//! .into_iter()
//! .map(|component| component.to_string_lossy().into_owned())
//! .collect::<Vec<_>>(),
//! vec!["src", "lib.rs"]
//! );
//!
//! #[derive(Default)]
//! struct Recorder {
//! directories: Vec<PathBuf>,
//! paths: Vec<PathBuf>,
//! }
//!
//! impl Delegate for Recorder {
//! fn push_directory(&mut self, stack: &Stack) -> std::io::Result<()> {
//! self.directories.push(stack.current_relative().to_path_buf());
//! Ok(())
//! }
//!
//! fn push(&mut self, _is_last_component: bool, stack: &Stack) -> std::io::Result<()> {
//! self.paths.push(stack.current_relative().to_path_buf());
//! Ok(())
//! }
//!
//! fn pop_directory(&mut self) {}
//! }
//!
//! # let dir = tempfile::tempdir()?;
//! let capabilities = gix_fs::Capabilities::probe_dir(dir.path());
//! let mut stack = Stack::new(dir.path().to_path_buf());
//! let mut recorder = Recorder::default();
//! stack.make_relative_path_current("src/lib.rs", &mut recorder)?;
//!
//! assert_eq!(stack.current_relative(), Path::new("src/lib.rs"));
//! assert_eq!(recorder.directories[0], Path::new(""));
//! assert_eq!(recorder.paths, vec![PathBuf::from("src"), PathBuf::from("src/lib.rs")]);
//! assert_eq!(gix_fs::current_dir(capabilities.precompose_unicode)?, std::env::current_dir()?);
//! # Ok(()) }
//! ```
use PathBuf;
/// Common knowledge about the worktree that is needed across most interactions with the work tree
pub use ;
///
///
pub use read_dir;
///
/// Like [`std::env::current_dir()`], but it will `precompose_unicode` if that value is true, if the current directory
/// is valid unicode and if there are decomposed unicode codepoints.
///
/// Thus, it will turn `"a\u{308}"` into `ä` if `true`.
/// Keeping it `false` will not alter the output.
///
/// Note that `precompose_unicode` most be set using the `core.precomposeUnicode` git configuration.
/// A stack of path components with the delegation of side-effects as the currently set path changes, component by component.
/// Returns whether a file has the executable permission set.
/// Classifiers for IO-errors.
/// Returns whether a file has the executable permission set.
///