Skip to content

Commit 1755c81

Browse files
committed
adjust to changes in gix-attributes
1 parent 424ad62 commit 1755c81

File tree

14 files changed

+298
-230
lines changed

14 files changed

+298
-230
lines changed

Cargo.lock

+247-191
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gitoxide-core/src/repository/exclude.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ pub fn query(
3535
.worktree()
3636
.with_context(|| "Cannot check excludes without a current worktree")?;
3737
let index = worktree.index()?;
38-
let mut cache = worktree.excludes(
39-
&index,
40-
Some(gix::attrs::MatchGroup::<gix::attrs::Ignore>::from_overrides(overrides)),
41-
)?;
38+
let mut cache = worktree.excludes(&index, Some(gix::ignore::Search::from_overrides(overrides)))?;
4239

4340
let prefix = repo.prefix().expect("worktree - we have an index by now")?;
4441

gix-worktree/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ required-features = ["internal-testing-to-avoid-being-run-by-cargo-test-all"]
2424

2525
[features]
2626
## Data structures implement `serde::Serialize` and `serde::Deserialize`.
27-
serde1 = [ "serde", "bstr/serde", "gix-index/serde1", "gix-hash/serde1", "gix-object/serde1" ]
27+
serde1 = [ "serde", "bstr/serde", "gix-index/serde1", "gix-hash/serde1", "gix-object/serde1", "gix-attributes/serde1", "gix-ignore/serde1" ]
2828

2929
internal-testing-gix-features-parallel = ["gix-features/parallel"]
3030
internal-testing-to-avoid-being-run-by-cargo-test-all = []
@@ -37,6 +37,7 @@ gix-object = { version = "^0.28.0", path = "../gix-object" }
3737
gix-glob = { version = "^0.5.5", path = "../gix-glob" }
3838
gix-path = { version = "^0.7.3", path = "../gix-path" }
3939
gix-attributes = { version = "^0.10.0", path = "../gix-attributes" }
40+
gix-ignore = { version = "^0.1.0", path = "../gix-ignore" }
4041
gix-features = { version = "^0.28.0", path = "../gix-features" }
4142

4243
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}

gix-worktree/src/fs/cache/platform.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'a> Platform<'a> {
3434
/// # Panics
3535
///
3636
/// If the cache was configured without exclude patterns.
37-
pub fn matching_exclude_pattern(&self) -> Option<gix_attributes::Match<'_, ()>> {
37+
pub fn matching_exclude_pattern(&self) -> Option<gix_ignore::search::Match<'_, ()>> {
3838
let ignore = self.parent.state.ignore_or_panic();
3939
let relative_path =
4040
gix_path::to_unix_separators_on_windows(gix_path::into_bstr(self.parent.stack.current_relative.as_path()));

gix-worktree/src/fs/cache/state.rs

+27-12
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use gix_hash::oid;
66

77
use crate::fs::{cache::State, PathOidMapping};
88

9-
type AttributeMatchGroup = gix_attributes::MatchGroup<gix_attributes::Attributes>;
10-
type IgnoreMatchGroup = gix_attributes::MatchGroup<gix_attributes::Ignore>;
9+
type AttributeMatchGroup = gix_attributes::Search;
10+
type IgnoreMatchGroup = gix_ignore::Search;
1111

1212
/// State related to attributes associated with files in the repository.
1313
#[derive(Default, Clone)]
@@ -44,6 +44,8 @@ pub struct Ignore {
4444
impl Ignore {
4545
/// The `exclude_file_name_for_directories` is an optional override for the filename to use when checking per-directory
4646
/// ignore files within the repository, defaults to`.gitignore`.
47+
///
48+
// This is what it should be able represent: https://github.com/git/git/blob/140b9478dad5d19543c1cb4fd293ccec228f1240/dir.c#L3354
4749
// TODO: more docs
4850
pub fn new(
4951
overrides: IgnoreMatchGroup,
@@ -79,7 +81,7 @@ impl Ignore {
7981
relative_path: &BStr,
8082
is_dir: Option<bool>,
8183
case: Case,
82-
) -> Option<gix_attributes::Match<'_, ()>> {
84+
) -> Option<gix_ignore::search::Match<'_, ()>> {
8385
let groups = self.match_groups();
8486
let mut dir_match = None;
8587
if let Some((source, mapping)) = self
@@ -93,7 +95,7 @@ impl Ignore {
9395
})
9496
.next()
9597
{
96-
let match_ = gix_attributes::Match {
98+
let match_ = gix_ignore::search::Match {
9799
pattern: &mapping.pattern,
98100
value: &mapping.value,
99101
sequence_number: mapping.sequence_number,
@@ -135,8 +137,14 @@ impl Ignore {
135137
.enumerate()
136138
.rev()
137139
.find_map(|(plidx, pl)| {
138-
pl.pattern_idx_matching_relative_path(relative_path, basename_pos, is_dir, case)
139-
.map(|idx| (plidx, idx))
140+
gix_ignore::search::pattern_idx_matching_relative_path(
141+
pl,
142+
relative_path,
143+
basename_pos,
144+
is_dir,
145+
case,
146+
)
147+
.map(|idx| (plidx, idx))
140148
})
141149
.map(|(plidx, pidx)| (gidx, plidx, pidx))
142150
})
@@ -163,17 +171,24 @@ impl Ignore {
163171
let ignore_file_in_index =
164172
attribute_files_in_index.binary_search_by(|t| t.0.as_bstr().cmp(ignore_path_relative.as_ref()));
165173
let follow_symlinks = ignore_file_in_index.is_err();
166-
if !self
167-
.stack
168-
.add_patterns_file(dir.join(".gitignore"), follow_symlinks, Some(root), buf)?
169-
{
174+
if !gix_glob::search::add_patterns_file(
175+
&mut self.stack.patterns,
176+
dir.join(".gitignore"),
177+
follow_symlinks,
178+
Some(root),
179+
buf,
180+
)? {
170181
match ignore_file_in_index {
171182
Ok(idx) => {
172183
let ignore_blob = find(&attribute_files_in_index[idx].1, buf)
173184
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?;
174185
let ignore_path = gix_path::from_bstring(ignore_path_relative.into_owned());
175-
self.stack
176-
.add_patterns_buffer(ignore_blob.data, ignore_path, Some(root));
186+
gix_glob::search::add_patterns_buffer(
187+
&mut self.stack.patterns,
188+
ignore_blob.data,
189+
ignore_path,
190+
Some(root),
191+
);
177192
}
178193
Err(_) => {
179194
// Need one stack level per component so push and pop matches.

gix-worktree/src/index/checkout.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![allow(missing_docs)]
22
use bstr::BString;
3-
use gix_attributes::Attributes;
43
use gix_utils::FilesystemCapabilities;
54

65
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
@@ -61,7 +60,7 @@ pub struct Options {
6160
/// Default true.
6261
pub check_stat: bool,
6362
/// A group of attribute patterns that are applied globally, i.e. aren't rooted within the repository itself.
64-
pub attribute_globals: gix_attributes::MatchGroup<Attributes>,
63+
pub attribute_globals: gix_attributes::Search,
6564
}
6665

6766
impl Default for Options {

gix-worktree/tests/worktree/fs/cache/ignore_and_attributes.rs renamed to gix-worktree/tests/worktree/fs/cache/ignore.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn special_exclude_cases_we_handle_differently() {
4545
Default::default(),
4646
gix_worktree::fs::cache::state::Ignore::new(
4747
Default::default(),
48-
gix_attributes::MatchGroup::from_git_dir(&git_dir, None, &mut buf).unwrap(),
48+
gix_ignore::Search::from_git_dir(&git_dir, None, &mut buf).unwrap(),
4949
None,
5050
case,
5151
),
@@ -99,8 +99,8 @@ fn check_against_baseline() -> crate::Result {
9999
let state = gix_worktree::fs::cache::State::for_add(
100100
Default::default(), // TODO: attribute tests
101101
gix_worktree::fs::cache::state::Ignore::new(
102-
gix_attributes::MatchGroup::from_overrides(vec!["!force-include"]),
103-
gix_attributes::MatchGroup::from_git_dir(&git_dir, Some(user_exclude_path), &mut buf)?,
102+
gix_ignore::Search::from_overrides(vec!["!force-include"]),
103+
gix_ignore::Search::from_git_dir(&git_dir, Some(user_exclude_path), &mut buf)?,
104104
None,
105105
case,
106106
),
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
mod create_directory;
22

33
#[allow(unused)]
4-
mod ignore_and_attributes;
4+
mod ignore;

gix/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ serde1 = [ "serde",
6565
"gix-mailmap/serde1",
6666
"gix-url/serde1",
6767
"gix-attributes/serde1",
68+
"gix-ignore/serde1",
6869
"gix-revision/serde1",
6970
"gix-credentials/serde1" ]
7071

@@ -138,6 +139,7 @@ gix-mailmap = { version = "^0.11.0", path = "../gix-mailmap" }
138139
gix-features = { version = "^0.28.1", path = "../gix-features", features = ["progress", "once_cell"] }
139140

140141
gix-attributes = { version = "^0.10.0", path = "../gix-attributes" }
142+
gix-ignore = { version = "^0.1.0", path = "../gix-ignore" }
141143
gix-glob = { version = "^0.5.5", path = "../gix-glob" }
142144
gix-credentials = { version = "^0.12.0", path = "../gix-credentials" }
143145
gix-prompt = { version = "^0.3.3", path = "../gix-prompt" }

gix/src/config/cache/access.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ impl Cache {
157157
fn assemble_attribute_globals(
158158
me: &Cache,
159159
_git_dir: &std::path::Path,
160-
) -> Result<gix_attributes::MatchGroup, checkout_options::Error> {
160+
) -> Result<gix_attributes::Search, checkout_options::Error> {
161161
let _attributes_file = match me
162162
.trusted_file_path("core", None, Core::ATTRIBUTES_FILE.name)
163163
.transpose()?
164164
{
165165
Some(attributes) => Some(attributes.into_owned()),
166166
None => me.xdg_config_path("attributes").ok().flatten(),
167167
};
168-
// TODO: implement gix_attributes::MatchGroup::<gix_attributes::Attributes>::from_git_dir(), similar to what's done for `Ignore`.
168+
// TODO: implement gix_attributes::Search::from_git_dir(), similar to what's done for `Ignore`.
169169
Ok(Default::default())
170170
}
171171

@@ -203,7 +203,7 @@ impl Cache {
203203
std::env::var_os("XDG_CONFIG_HOME")
204204
.map(|path| (PathBuf::from(path), &self.xdg_config_home_env))
205205
.or_else(|| {
206-
gix_path::home_dir().map(|mut p| {
206+
gix_path::env::home_dir().map(|mut p| {
207207
(
208208
{
209209
p.push(".config");
@@ -225,6 +225,6 @@ impl Cache {
225225
/// We never fail for here even if the permission is set to deny as we `gix-config` will fail later
226226
/// if it actually wants to use the home directory - we don't want to fail prematurely.
227227
pub(crate) fn home_dir(&self) -> Option<PathBuf> {
228-
gix_path::home_dir().and_then(|path| self.home_env.check_opt(path))
228+
gix_path::env::home_dir().and_then(|path| self.home_env.check_opt(path))
229229
}
230230
}

gix/src/config/cache/init.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl Cache {
9595
"HOME" => Some(home_env),
9696
_ => None,
9797
}
98-
.and_then(|perm| perm.check_opt(name).and_then(gix_path::env_var))
98+
.and_then(|perm| perm.check_opt(name).and_then(gix_path::env::var))
9999
})
100100
.map(|p| (source, p.into_owned()))
101101
})

gix/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ use gix_features::threading::OwnShared;
7575
pub use gix_features::{parallel, progress::Progress, threading};
7676
pub use gix_glob as glob;
7777
pub use gix_hash as hash;
78+
pub use gix_ignore as ignore;
7879
#[doc(inline)]
7980
pub use gix_index as index;
8081
pub use gix_lock as lock;

gix/src/open/repository.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl ThreadSafeRepository {
180180
};
181181
let head = refs.find("HEAD").ok();
182182
let git_install_dir = crate::path::install_dir().ok();
183-
let home = gix_path::home_dir().and_then(|home| env.home.check_opt(home));
183+
let home = gix_path::env::home_dir().and_then(|home| env.home.check_opt(home));
184184

185185
let mut filter_config_section = filter_config_section.unwrap_or(config::section::is_trusted);
186186
let config = config::Cache::from_stage_one(

gix/src/worktree/mod.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,20 @@ pub mod excludes {
119119
impl<'repo> crate::Worktree<'repo> {
120120
/// Configure a file-system cache checking if files below the repository are excluded.
121121
///
122-
/// This takes into consideration all the usual repository configuration.
122+
/// This takes into consideration all the usual repository configuration, namely:
123+
///
124+
/// * `$XDG_CONFIG_HOME/…/ignore` if `core.excludesFile` is *not* set, otherwise use the configured file.
125+
/// * `$GIT_DIR/info/exclude` if present.
123126
///
124127
/// `index` may be used to obtain `.gitignore` files directly from the index under certain conditions.
125128
// TODO: test, provide higher-level interface that is much easier to use and doesn't panic when accessing entries
126129
// by non-relative path.
127130
// TODO: `index` might be so special (given the conditions we are talking about) that it's better obtained internally
128131
// so the caller won't have to care.
129-
// TODO: global files like `~/.gitignore` seem to be missing here, but we need a way to control if these should be loaded.
130-
// probably that needs another permission in the repo options or a custom config variable. The latter is easiest to manage.
131132
pub fn excludes(
132133
&self,
133134
index: &gix_index::State,
134-
overrides: Option<gix_attributes::MatchGroup<gix_attributes::Ignore>>,
135+
overrides: Option<gix_ignore::Search>,
135136
) -> Result<gix_worktree::fs::Cache, Error> {
136137
let repo = self.parent;
137138
let case = if repo.config.ignore_case {
@@ -146,11 +147,7 @@ pub mod excludes {
146147
};
147148
let state = gix_worktree::fs::cache::State::IgnoreStack(gix_worktree::fs::cache::state::Ignore::new(
148149
overrides.unwrap_or_default(),
149-
gix_attributes::MatchGroup::<gix_attributes::Ignore>::from_git_dir(
150-
repo.git_dir(),
151-
excludes_file,
152-
&mut buf,
153-
)?,
150+
gix_ignore::Search::from_git_dir(repo.git_dir(), excludes_file, &mut buf)?,
154151
None,
155152
case,
156153
));

0 commit comments

Comments
 (0)