Skip to content

Commit f159775

Browse files
committed
feat!: add Stack::from_state_and_ignore_case().
It adds `Stack::from_state_and_ignore_case()` as utility to more easily instantiate a stack the is configured correctly. This also removes the `stack::State::for_status()` method as it's not actually suitable for status retrieval per se.
1 parent 0e10b62 commit f159775

File tree

7 files changed

+55
-22
lines changed

7 files changed

+55
-22
lines changed

gix-worktree/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
1111
#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
1212
use bstr::BString;
13+
pub use gix_glob;
1314

1415
/// A cache for efficiently executing operations on directories and files which are encountered in sorted order.
1516
/// That way, these operations can be re-used for subsequent invocations in the same directory.

gix-worktree/src/stack/delegate.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'a, 'find> gix_fs::stack::Delegate for StackDelegate<'a, 'find> {
5656
};
5757
match &mut self.state {
5858
#[cfg(feature = "attributes")]
59-
State::CreateDirectoryAndAttributesStack { attributes, .. } => {
59+
State::CreateDirectoryAndAttributesStack { attributes, .. } | State::AttributesStack(attributes) => {
6060
attributes.push_directory(
6161
stack.root(),
6262
stack.current(),
@@ -89,16 +89,6 @@ impl<'a, 'find> gix_fs::stack::Delegate for StackDelegate<'a, 'find> {
8989
&mut self.statistics.ignore,
9090
)?
9191
}
92-
#[cfg(feature = "attributes")]
93-
State::AttributesStack(attributes) => attributes.push_directory(
94-
stack.root(),
95-
stack.current(),
96-
rela_dir,
97-
self.buf,
98-
self.id_mappings,
99-
&mut self.find,
100-
&mut self.statistics.attributes,
101-
)?,
10292
State::IgnoreStack(ignore) => ignore.push_directory(
10393
stack.root(),
10494
stack.current(),
@@ -139,18 +129,14 @@ impl<'a, 'find> gix_fs::stack::Delegate for StackDelegate<'a, 'find> {
139129
self.statistics.delegate.pop_directory += 1;
140130
match &mut self.state {
141131
#[cfg(feature = "attributes")]
142-
State::CreateDirectoryAndAttributesStack { attributes, .. } => {
132+
State::CreateDirectoryAndAttributesStack { attributes, .. } | State::AttributesStack(attributes) => {
143133
attributes.pop_directory();
144134
}
145135
#[cfg(feature = "attributes")]
146136
State::AttributesAndIgnoreStack { attributes, ignore } => {
147137
attributes.pop_directory();
148138
ignore.pop_directory();
149139
}
150-
#[cfg(feature = "attributes")]
151-
State::AttributesStack(attributes) => {
152-
attributes.pop_directory();
153-
}
154140
State::IgnoreStack(ignore) => {
155141
ignore.pop_directory();
156142
}

gix-worktree/src/stack/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,27 @@ impl Stack {
7777
statistics: Statistics::default(),
7878
}
7979
}
80+
81+
/// Create a new stack that takes into consideration the `ignore_case` result of a filesystem probe in `root`. It takes a configured
82+
/// `state` to control what it can do, while initializing attribute or ignore files that are to be queried from the ODB using
83+
/// `index` and `path_backing`.
84+
///
85+
/// This is the easiest way to correctly setup a stack.
86+
pub fn from_state_and_ignore_case(
87+
root: impl Into<PathBuf>,
88+
ignore_case: bool,
89+
state: State,
90+
index: &gix_index::State,
91+
path_backing: &gix_index::PathStorageRef,
92+
) -> Self {
93+
let case = if ignore_case {
94+
gix_glob::pattern::Case::Fold
95+
} else {
96+
gix_glob::pattern::Case::Sensitive
97+
};
98+
let attribute_files = state.id_mappings_from_index(index, path_backing, case);
99+
Stack::new(root, state, case, Vec::with_capacity(512), attribute_files)
100+
}
80101
}
81102

82103
/// Entry points for attribute query

gix-worktree/src/stack/state/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ impl State {
7171
pub fn for_add(attributes: Attributes, ignore: Ignore) -> Self {
7272
State::AttributesAndIgnoreStack { attributes, ignore }
7373
}
74-
75-
/// Configure a state for status retrieval, which needs access to ignore files only.
76-
pub fn for_status(ignore: Ignore) -> Self {
77-
State::IgnoreStack(ignore)
78-
}
7974
}
8075

8176
/// Utilities
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
make_ignore_and_attributes_setup.tar.xz
22
make_attributes_baseline.tar.xz
3+
symlink_stack.tar.xz
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
git init base;
5+
(cd base
6+
touch file
7+
mkdir dir
8+
touch dir/file-in-dir
9+
(cd dir
10+
ln -s file-in-dir filelink
11+
mkdir subdir
12+
ln -s subdir dirlink
13+
)
14+
15+
ln -s file root-filelink
16+
ln -s dir root-dirlink
17+
18+
cat <<EOF > .gitattributes
19+
/file file-attr
20+
/dir/file-in-dir dir-file-attr
21+
EOF
22+
git add . && git commit -m "init"
23+
)
24+
25+
ln -s base symlink-base
26+

justfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ check:
6666
cargo check --features verbose-object-parsing-errors
6767
cd gix-attributes && cargo check --features serde
6868
cd gix-glob && cargo check --features serde
69-
cd gix-worktree && cargo check --features serde
69+
cd gix-worktree; \
70+
set -ex; \
71+
cargo check --features serde; \
72+
cargo check --no-default-features;
7073
cd gix-actor && cargo check --features serde
7174
cd gix-date && cargo check --features serde
7275
cargo check -p gix-tempfile --features signals

0 commit comments

Comments
 (0)