Skip to content

Commit 1ca6a3c

Browse files
committed
adapt to changes in gix-worktree
1 parent 9564699 commit 1ca6a3c

File tree

25 files changed

+156
-78
lines changed

25 files changed

+156
-78
lines changed

gitoxide-core/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,11 @@ pub use discover::discover;
8484

8585
#[cfg(all(feature = "async-client", feature = "blocking-client"))]
8686
compile_error!("Cannot set both 'blocking-client' and 'async-client' features as they are mutually exclusive");
87+
88+
fn is_dir_to_mode(is_dir: bool) -> gix::index::entry::Mode {
89+
if is_dir {
90+
gix::index::entry::Mode::DIR
91+
} else {
92+
gix::index::entry::Mode::FILE
93+
}
94+
}

gitoxide-core/src/repository/attributes/query.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub(crate) mod function {
1414
use gix::bstr::BStr;
1515

1616
use crate::{
17+
is_dir_to_mode,
1718
repository::{
1819
attributes::query::{attributes_cache, Options},
1920
PathsOrPatterns,
@@ -38,12 +39,12 @@ pub(crate) mod function {
3839
match input {
3940
PathsOrPatterns::Paths(paths) => {
4041
for path in paths {
41-
let is_dir = gix::path::from_bstr(Cow::Borrowed(path.as_ref()))
42+
let mode = gix::path::from_bstr(Cow::Borrowed(path.as_ref()))
4243
.metadata()
4344
.ok()
44-
.map(|m| m.is_dir());
45+
.map(|m| is_dir_to_mode(m.is_dir()));
4546

46-
let entry = cache.at_entry(path.as_slice(), is_dir)?;
47+
let entry = cache.at_entry(path.as_slice(), mode)?;
4748
if !entry.matching_attributes(&mut matches) {
4849
continue;
4950
}
@@ -61,9 +62,9 @@ pub(crate) mod function {
6162
)?;
6263
let mut pathspec_matched_entry = false;
6364
if let Some(it) = pathspec.index_entries_with_paths(&index) {
64-
for (path, _entry) in it {
65+
for (path, entry) in it {
6566
pathspec_matched_entry = true;
66-
let entry = cache.at_entry(path, Some(false))?;
67+
let entry = cache.at_entry(path, entry.mode.into())?;
6768
if !entry.matching_attributes(&mut matches) {
6869
continue;
6970
}
@@ -87,10 +88,10 @@ pub(crate) mod function {
8788
let path = pattern.path();
8889
let entry = cache.at_entry(
8990
path,
90-
Some(
91+
Some(is_dir_to_mode(
9192
workdir.map_or(false, |wd| wd.join(gix::path::from_bstr(path)).is_dir())
9293
|| pattern.signature.contains(gix::pathspec::MagicSignature::MUST_BE_DIR),
93-
),
94+
)),
9495
)?;
9596
if !entry.matching_attributes(&mut matches) {
9697
continue;

gitoxide-core/src/repository/attributes/validate_baseline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub(crate) mod function {
192192
);
193193

194194
for (rela_path, baseline) in rx_base {
195-
let entry = cache.at_entry(rela_path.as_str(), Some(false))?;
195+
let entry = cache.at_entry(rela_path.as_str(), None)?;
196196
match baseline {
197197
Baseline::Attribute { assignments: expected } => {
198198
entry.matching_attributes(&mut matches);

gitoxide-core/src/repository/exclude.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{borrow::Cow, io};
33
use anyhow::bail;
44
use gix::bstr::BStr;
55

6-
use crate::{repository::PathsOrPatterns, OutputFormat};
6+
use crate::{is_dir_to_mode, repository::PathsOrPatterns, OutputFormat};
77

88
pub mod query {
99
use std::ffi::OsString;
@@ -44,11 +44,11 @@ pub fn query(
4444
match input {
4545
PathsOrPatterns::Paths(paths) => {
4646
for path in paths {
47-
let is_dir = gix::path::from_bstr(Cow::Borrowed(path.as_ref()))
47+
let mode = gix::path::from_bstr(Cow::Borrowed(path.as_ref()))
4848
.metadata()
4949
.ok()
50-
.map(|m| m.is_dir());
51-
let entry = cache.at_entry(path.as_slice(), is_dir)?;
50+
.map(|m| is_dir_to_mode(m.is_dir()));
51+
let entry = cache.at_entry(path.as_slice(), mode)?;
5252
let match_ = entry
5353
.matching_exclude_pattern()
5454
.and_then(|m| (show_ignore_patterns || !m.pattern.is_negative()).then_some(m));
@@ -66,9 +66,9 @@ pub fn query(
6666
)?;
6767

6868
if let Some(it) = pathspec.index_entries_with_paths(&index) {
69-
for (path, _entry) in it {
69+
for (path, entry) in it {
7070
pathspec_matched_something = true;
71-
let entry = cache.at_entry(path, Some(false))?;
71+
let entry = cache.at_entry(path, entry.mode.into())?;
7272
let match_ = entry
7373
.matching_exclude_pattern()
7474
.and_then(|m| (show_ignore_patterns || !m.pattern.is_negative()).then_some(m));
@@ -92,10 +92,10 @@ pub fn query(
9292
let path = pattern.path();
9393
let entry = cache.at_entry(
9494
path,
95-
Some(
95+
Some(is_dir_to_mode(
9696
workdir.map_or(false, |wd| wd.join(gix::path::from_bstr(path)).is_dir())
9797
|| pattern.signature.contains(gix::pathspec::MagicSignature::MUST_BE_DIR),
98-
),
98+
)),
9999
)?;
100100
let match_ = entry
101101
.matching_exclude_pattern()

gitoxide-core/src/repository/index/entries.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub(crate) mod function {
3131
};
3232

3333
use crate::{
34+
is_dir_to_mode,
3435
repository::index::entries::{Attributes, Options},
3536
OutputFormat,
3637
};
@@ -174,7 +175,7 @@ pub(crate) mod function {
174175
}
175176
// The user doesn't want attributes, so we set the cache position on demand only
176177
None => cache
177-
.at_entry(rela_path, Some(is_dir))
178+
.at_entry(rela_path, Some(is_dir_to_mode(is_dir)))
178179
.ok()
179180
.map(|platform| platform.matching_attributes(out))
180181
.unwrap_or_default(),

gitoxide-core/src/repository/revision/resolve.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,10 @@ pub(crate) mod function {
127127
}
128128
gix::object::Kind::Blob if cache.is_some() && spec.path_and_mode().is_some() => {
129129
let (path, mode) = spec.path_and_mode().expect("is present");
130-
let is_dir = Some(mode.is_tree());
131130
match cache.expect("is some") {
132131
(BlobFormat::Git, _) => unreachable!("no need for a cache when querying object db"),
133132
(BlobFormat::Worktree, cache) => {
134-
let platform = cache.attr_stack.at_entry(path, is_dir, &repo.objects)?;
133+
let platform = cache.attr_stack.at_entry(path, Some(mode.into()), &repo.objects)?;
135134
let object = id.object()?;
136135
let mut converted = cache.filter.worktree_filter.convert_to_worktree(
137136
&object.data,

gix-archive/tests/archive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ mod from_tree {
233233
noop_pipeline(),
234234
move |rela_path, mode, attrs| {
235235
cache
236-
.at_entry(rela_path, mode.is_tree().into(), &odb)
236+
.at_entry(rela_path, Some(mode.into()), &odb)
237237
.map(|entry| entry.matching_attributes(attrs))
238238
.map(|_| ())
239239
},

gix-diff/src/blob/platform.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -583,14 +583,14 @@ impl Platform {
583583
if self.diff_cache.contains_key(storage) {
584584
return Ok(());
585585
}
586-
let entry = self
587-
.attr_stack
588-
.at_entry(rela_path, Some(false), objects)
589-
.map_err(|err| set_resource::Error::Attributes {
590-
source: err,
591-
kind,
592-
rela_path: rela_path.to_owned(),
593-
})?;
586+
let entry =
587+
self.attr_stack
588+
.at_entry(rela_path, None, objects)
589+
.map_err(|err| set_resource::Error::Attributes {
590+
source: err,
591+
kind,
592+
rela_path: rela_path.to_owned(),
593+
})?;
594594
let mut buf = Vec::new();
595595
let out = self.filter.convert_to_diffable(
596596
&id,

gix-diff/tests/blob/pipeline.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ pub(crate) mod convert_to_diffable {
507507
assert_eq!(out.data, Some(pipeline::Data::Binary { size: 11 }));
508508
assert_eq!(buf.len(), 0, "buffers are cleared even if we read them");
509509

510-
let platform = attributes.at_entry("c", Some(false), &gix_object::find::Never)?;
510+
let platform = attributes.at_entry("c", None, &gix_object::find::Never)?;
511511

512512
let id = db.insert("b");
513513
let out = filter.convert_to_diffable(
@@ -589,7 +589,7 @@ pub(crate) mod convert_to_diffable {
589589
let mut db = ObjectDb::default();
590590
let null = gix_hash::Kind::Sha1.null();
591591
let mut buf = Vec::new();
592-
let platform = attributes.at_entry("a", Some(false), &gix_object::find::Never)?;
592+
let platform = attributes.at_entry("a", None, &gix_object::find::Never)?;
593593
let worktree_modes = [
594594
pipeline::Mode::ToWorktreeAndBinaryToText,
595595
pipeline::Mode::ToGitUnlessBinaryToTextIsPresent,
@@ -672,7 +672,7 @@ pub(crate) mod convert_to_diffable {
672672
"no filter was applied in this mode, also when using the ODB"
673673
);
674674

675-
let platform = attributes.at_entry("missing", Some(false), &gix_object::find::Never)?;
675+
let platform = attributes.at_entry("missing", None, &gix_object::find::Never)?;
676676
for mode in all_modes {
677677
buf.push(1);
678678
let out = filter.convert_to_diffable(
@@ -731,7 +731,7 @@ pub(crate) mod convert_to_diffable {
731731
);
732732
}
733733

734-
let platform = attributes.at_entry("b", Some(false), &gix_object::find::Never)?;
734+
let platform = attributes.at_entry("b", None, &gix_object::find::Never)?;
735735
for mode in all_modes {
736736
buf.push(1);
737737
let out = filter.convert_to_diffable(
@@ -781,7 +781,7 @@ pub(crate) mod convert_to_diffable {
781781
assert_eq!(buf.len(), 0, "it's always cleared before any potential use");
782782
}
783783

784-
let platform = attributes.at_entry("c", Some(false), &gix_object::find::Never)?;
784+
let platform = attributes.at_entry("c", None, &gix_object::find::Never)?;
785785
for mode in worktree_modes {
786786
let out = filter.convert_to_diffable(
787787
&null,
@@ -827,7 +827,7 @@ pub(crate) mod convert_to_diffable {
827827
);
828828
}
829829

830-
let platform = attributes.at_entry("unset", Some(false), &gix_object::find::Never)?;
830+
let platform = attributes.at_entry("unset", None, &gix_object::find::Never)?;
831831
for mode in all_modes {
832832
let out = filter.convert_to_diffable(
833833
&null,
@@ -879,7 +879,7 @@ pub(crate) mod convert_to_diffable {
879879
assert_eq!(buf.len(), 0);
880880
}
881881

882-
let platform = attributes.at_entry("d", Some(false), &gix_object::find::Never)?;
882+
let platform = attributes.at_entry("d", None, &gix_object::find::Never)?;
883883
let id = db.insert("d-in-db");
884884
for mode in worktree_modes {
885885
let out = filter.convert_to_diffable(
@@ -923,7 +923,7 @@ pub(crate) mod convert_to_diffable {
923923
);
924924
}
925925

926-
let platform = attributes.at_entry("e-no-attr", Some(false), &gix_object::find::Never)?;
926+
let platform = attributes.at_entry("e-no-attr", None, &gix_object::find::Never)?;
927927
let out = filter.convert_to_diffable(
928928
&null,
929929
EntryKind::Blob,

gix-dir/src/walk/classify.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,17 @@ pub fn path(
161161
.as_mut()
162162
.map_or(Ok(None), |stack| {
163163
stack
164-
.at_entry(rela_path.as_bstr(), disk_kind.map(|ft| ft.is_dir()), ctx.objects)
164+
.at_entry(
165+
rela_path.as_bstr(),
166+
disk_kind.map(|ft| {
167+
if ft.is_dir() {
168+
gix_index::entry::Mode::DIR
169+
} else {
170+
gix_index::entry::Mode::FILE
171+
}
172+
}),
173+
ctx.objects,
174+
)
165175
.map(|platform| platform.excluded_kind())
166176
})
167177
.map_err(Error::ExcludesAccess)?
@@ -203,9 +213,9 @@ pub fn path(
203213
&& ctx.excludes.is_some()
204214
&& kind.map_or(false, |ft| ft == entry::Kind::Symlink)
205215
{
206-
path.metadata().ok().map(|md| md.is_dir()).or(Some(false))
216+
path.metadata().ok().map(|md| is_dir_to_mode(md.is_dir()))
207217
} else {
208-
kind.map(|ft| ft.is_dir())
218+
kind.map(|ft| is_dir_to_mode(ft.is_dir()))
209219
};
210220

211221
let mut maybe_upgrade_to_repository = |current_kind, find_harder: bool| {
@@ -408,3 +418,11 @@ fn is_eq(lhs: &BStr, rhs: impl AsRef<BStr>, ignore_case: bool) -> bool {
408418
lhs == rhs.as_ref()
409419
}
410420
}
421+
422+
fn is_dir_to_mode(is_dir: bool) -> gix_index::entry::Mode {
423+
if is_dir {
424+
gix_index::entry::Mode::DIR
425+
} else {
426+
gix_index::entry::Mode::FILE
427+
}
428+
}

gix-filter/tests/pipeline/convert_to_git.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn all_stages_mean_streaming_is_impossible() -> gix_testtools::Result {
5353
Path::new("any.txt"),
5454
&mut |path, attrs| {
5555
cache
56-
.at_entry(path, Some(false), &gix_object::find::Never)
56+
.at_entry(path, None, &gix_object::find::Never)
5757
.expect("cannot fail")
5858
.matching_attributes(attrs);
5959
},
@@ -82,7 +82,7 @@ fn only_driver_means_streaming_is_possible() -> gix_testtools::Result {
8282
Path::new("subdir/doesnot/matter/any.txt"),
8383
&mut |path, attrs| {
8484
cache
85-
.at_entry(path, Some(false), &gix_object::find::Never)
85+
.at_entry(path, None, &gix_object::find::Never)
8686
.expect("cannot fail")
8787
.matching_attributes(attrs);
8888
},
@@ -112,7 +112,7 @@ fn no_filter_means_reader_is_returned_unchanged() -> gix_testtools::Result {
112112
Path::new("other.txt"),
113113
&mut |path, attrs| {
114114
cache
115-
.at_entry(path, Some(false), &gix_object::find::Never)
115+
.at_entry(path, None, &gix_object::find::Never)
116116
.expect("cannot fail")
117117
.matching_attributes(attrs);
118118
},

gix-filter/tests/pipeline/convert_to_worktree.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn all_stages() -> gix_testtools::Result {
2121
"any.txt".into(),
2222
&mut |path, attrs| {
2323
cache
24-
.at_entry(path, Some(false), &gix_object::find::Never)
24+
.at_entry(path, None, &gix_object::find::Never)
2525
.expect("cannot fail")
2626
.matching_attributes(attrs);
2727
},
@@ -54,7 +54,7 @@ fn all_stages_no_filter() -> gix_testtools::Result {
5454
"other.txt".into(),
5555
&mut |path, attrs| {
5656
cache
57-
.at_entry(path, Some(false), &gix_object::find::Never)
57+
.at_entry(path, None, &gix_object::find::Never)
5858
.expect("cannot fail")
5959
.matching_attributes(attrs);
6060
},
@@ -86,7 +86,7 @@ fn no_filter() -> gix_testtools::Result {
8686
"other.txt".into(),
8787
&mut |path, attrs| {
8888
cache
89-
.at_entry(path, Some(false), &gix_object::find::Never)
89+
.at_entry(path, None, &gix_object::find::Never)
9090
.expect("cannot fail")
9191
.matching_attributes(attrs);
9292
},

gix-status/src/index_as_worktree/function.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,15 @@ impl<'index> State<'_, 'index> {
276276
&mut |relative_path, case, is_dir, out| {
277277
self.attr_stack
278278
.set_case(case)
279-
.at_entry(relative_path, Some(is_dir), objects)
279+
.at_entry(
280+
relative_path,
281+
Some(if is_dir {
282+
gix_index::entry::Mode::DIR
283+
} else {
284+
gix_index::entry::Mode::FILE
285+
}),
286+
objects,
287+
)
280288
.map_or(false, |platform| platform.matching_attributes(out))
281289
},
282290
)
@@ -541,7 +549,9 @@ where
541549
}
542550
} else {
543551
self.buf.clear();
544-
let platform = self.attr_stack.at_entry(self.rela_path, Some(false), &self.objects)?;
552+
let platform = self
553+
.attr_stack
554+
.at_entry(self.rela_path, Some(self.entry.mode), &self.objects)?;
545555
let file = std::fs::File::open(self.path)?;
546556
let out = self
547557
.filter

0 commit comments

Comments
 (0)