Skip to content

Commit

Permalink
Merge pull request from GHSA-7w47-3wg8-547c
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed May 22, 2024
2 parents 3c21741 + 1242151 commit 79dce79
Show file tree
Hide file tree
Showing 97 changed files with 2,268 additions and 347 deletions.
286 changes: 272 additions & 14 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions gitoxide-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,11 @@ pub use discover::discover;

#[cfg(all(feature = "async-client", feature = "blocking-client"))]
compile_error!("Cannot set both 'blocking-client' and 'async-client' features as they are mutually exclusive");

fn is_dir_to_mode(is_dir: bool) -> gix::index::entry::Mode {
if is_dir {
gix::index::entry::Mode::DIR
} else {
gix::index::entry::Mode::FILE
}
}
15 changes: 8 additions & 7 deletions gitoxide-core/src/repository/attributes/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub(crate) mod function {
use gix::bstr::BStr;

use crate::{
is_dir_to_mode,
repository::{
attributes::query::{attributes_cache, Options},
PathsOrPatterns,
Expand All @@ -38,12 +39,12 @@ pub(crate) mod function {
match input {
PathsOrPatterns::Paths(paths) => {
for path in paths {
let is_dir = gix::path::from_bstr(Cow::Borrowed(path.as_ref()))
let mode = gix::path::from_bstr(Cow::Borrowed(path.as_ref()))
.metadata()
.ok()
.map(|m| m.is_dir());
.map(|m| is_dir_to_mode(m.is_dir()));

let entry = cache.at_entry(path.as_slice(), is_dir)?;
let entry = cache.at_entry(path.as_slice(), mode)?;
if !entry.matching_attributes(&mut matches) {
continue;
}
Expand All @@ -61,9 +62,9 @@ pub(crate) mod function {
)?;
let mut pathspec_matched_entry = false;
if let Some(it) = pathspec.index_entries_with_paths(&index) {
for (path, _entry) in it {
for (path, entry) in it {
pathspec_matched_entry = true;
let entry = cache.at_entry(path, Some(false))?;
let entry = cache.at_entry(path, entry.mode.into())?;
if !entry.matching_attributes(&mut matches) {
continue;
}
Expand All @@ -87,10 +88,10 @@ pub(crate) mod function {
let path = pattern.path();
let entry = cache.at_entry(
path,
Some(
Some(is_dir_to_mode(
workdir.map_or(false, |wd| wd.join(gix::path::from_bstr(path)).is_dir())
|| pattern.signature.contains(gix::pathspec::MagicSignature::MUST_BE_DIR),
),
)),
)?;
if !entry.matching_attributes(&mut matches) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub(crate) mod function {
);

for (rela_path, baseline) in rx_base {
let entry = cache.at_entry(rela_path.as_str(), Some(false))?;
let entry = cache.at_entry(rela_path.as_str(), None)?;
match baseline {
Baseline::Attribute { assignments: expected } => {
entry.matching_attributes(&mut matches);
Expand Down
16 changes: 8 additions & 8 deletions gitoxide-core/src/repository/exclude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{borrow::Cow, io};
use anyhow::bail;
use gix::bstr::BStr;

use crate::{repository::PathsOrPatterns, OutputFormat};
use crate::{is_dir_to_mode, repository::PathsOrPatterns, OutputFormat};

pub mod query {
use std::ffi::OsString;
Expand Down Expand Up @@ -44,11 +44,11 @@ pub fn query(
match input {
PathsOrPatterns::Paths(paths) => {
for path in paths {
let is_dir = gix::path::from_bstr(Cow::Borrowed(path.as_ref()))
let mode = gix::path::from_bstr(Cow::Borrowed(path.as_ref()))
.metadata()
.ok()
.map(|m| m.is_dir());
let entry = cache.at_entry(path.as_slice(), is_dir)?;
.map(|m| is_dir_to_mode(m.is_dir()));
let entry = cache.at_entry(path.as_slice(), mode)?;
let match_ = entry
.matching_exclude_pattern()
.and_then(|m| (show_ignore_patterns || !m.pattern.is_negative()).then_some(m));
Expand All @@ -66,9 +66,9 @@ pub fn query(
)?;

if let Some(it) = pathspec.index_entries_with_paths(&index) {
for (path, _entry) in it {
for (path, entry) in it {
pathspec_matched_something = true;
let entry = cache.at_entry(path, Some(false))?;
let entry = cache.at_entry(path, entry.mode.into())?;
let match_ = entry
.matching_exclude_pattern()
.and_then(|m| (show_ignore_patterns || !m.pattern.is_negative()).then_some(m));
Expand All @@ -92,10 +92,10 @@ pub fn query(
let path = pattern.path();
let entry = cache.at_entry(
path,
Some(
Some(is_dir_to_mode(
workdir.map_or(false, |wd| wd.join(gix::path::from_bstr(path)).is_dir())
|| pattern.signature.contains(gix::pathspec::MagicSignature::MUST_BE_DIR),
),
)),
)?;
let match_ = entry
.matching_exclude_pattern()
Expand Down
3 changes: 2 additions & 1 deletion gitoxide-core/src/repository/index/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub(crate) mod function {
};

use crate::{
is_dir_to_mode,
repository::index::entries::{Attributes, Options},
OutputFormat,
};
Expand Down Expand Up @@ -174,7 +175,7 @@ pub(crate) mod function {
}
// The user doesn't want attributes, so we set the cache position on demand only
None => cache
.at_entry(rela_path, Some(is_dir))
.at_entry(rela_path, Some(is_dir_to_mode(is_dir)))
.ok()
.map(|platform| platform.matching_attributes(out))
.unwrap_or_default(),
Expand Down
3 changes: 1 addition & 2 deletions gitoxide-core/src/repository/revision/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,10 @@ pub(crate) mod function {
}
gix::object::Kind::Blob if cache.is_some() && spec.path_and_mode().is_some() => {
let (path, mode) = spec.path_and_mode().expect("is present");
let is_dir = Some(mode.is_tree());
match cache.expect("is some") {
(BlobFormat::Git, _) => unreachable!("no need for a cache when querying object db"),
(BlobFormat::Worktree, cache) => {
let platform = cache.attr_stack.at_entry(path, is_dir, &repo.objects)?;
let platform = cache.attr_stack.at_entry(path, Some(mode.into()), &repo.objects)?;
let object = id.object()?;
let mut converted = cache.filter.worktree_filter.convert_to_worktree(
&object.data,
Expand Down
2 changes: 1 addition & 1 deletion gix-archive/tests/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ mod from_tree {
noop_pipeline(),
move |rela_path, mode, attrs| {
cache
.at_entry(rela_path, mode.is_tree().into(), &odb)
.at_entry(rela_path, Some(mode.into()), &odb)
.map(|entry| entry.matching_attributes(attrs))
.map(|_| ())
},
Expand Down
16 changes: 8 additions & 8 deletions gix-diff/src/blob/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,14 +583,14 @@ impl Platform {
if self.diff_cache.contains_key(storage) {
return Ok(());
}
let entry = self
.attr_stack
.at_entry(rela_path, Some(false), objects)
.map_err(|err| set_resource::Error::Attributes {
source: err,
kind,
rela_path: rela_path.to_owned(),
})?;
let entry =
self.attr_stack
.at_entry(rela_path, None, objects)
.map_err(|err| set_resource::Error::Attributes {
source: err,
kind,
rela_path: rela_path.to_owned(),
})?;
let mut buf = Vec::new();
let out = self.filter.convert_to_diffable(
&id,
Expand Down
16 changes: 8 additions & 8 deletions gix-diff/tests/blob/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ pub(crate) mod convert_to_diffable {
assert_eq!(out.data, Some(pipeline::Data::Binary { size: 11 }));
assert_eq!(buf.len(), 0, "buffers are cleared even if we read them");

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

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

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

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

let platform = attributes.at_entry("c", Some(false), &gix_object::find::Never)?;
let platform = attributes.at_entry("c", None, &gix_object::find::Never)?;
for mode in worktree_modes {
let out = filter.convert_to_diffable(
&null,
Expand Down Expand Up @@ -827,7 +827,7 @@ pub(crate) mod convert_to_diffable {
);
}

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

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

let platform = attributes.at_entry("e-no-attr", Some(false), &gix_object::find::Never)?;
let platform = attributes.at_entry("e-no-attr", None, &gix_object::find::Never)?;
let out = filter.convert_to_diffable(
&null,
EntryKind::Blob,
Expand Down
18 changes: 15 additions & 3 deletions gix-dir/src/walk/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ pub fn path(
.as_mut()
.map_or(Ok(None), |stack| {
stack
.at_entry(rela_path.as_bstr(), disk_kind.map(|ft| ft.is_dir()), ctx.objects)
.at_entry(
rela_path.as_bstr(),
disk_kind.map(|ft| is_dir_to_mode(ft.is_dir())),
ctx.objects,
)
.map(|platform| platform.excluded_kind())
})
.map_err(Error::ExcludesAccess)?
Expand Down Expand Up @@ -203,9 +207,9 @@ pub fn path(
&& ctx.excludes.is_some()
&& kind.map_or(false, |ft| ft == entry::Kind::Symlink)
{
path.metadata().ok().map(|md| md.is_dir()).or(Some(false))
path.metadata().ok().map(|md| is_dir_to_mode(md.is_dir()))
} else {
kind.map(|ft| ft.is_dir())
kind.map(|ft| is_dir_to_mode(ft.is_dir()))
};

let mut maybe_upgrade_to_repository = |current_kind, find_harder: bool| {
Expand Down Expand Up @@ -408,3 +412,11 @@ fn is_eq(lhs: &BStr, rhs: impl AsRef<BStr>, ignore_case: bool) -> bool {
lhs == rhs.as_ref()
}
}

fn is_dir_to_mode(is_dir: bool) -> gix_index::entry::Mode {
if is_dir {
gix_index::entry::Mode::DIR
} else {
gix_index::entry::Mode::FILE
}
}
8 changes: 1 addition & 7 deletions gix-discover/src/is.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,7 @@ pub(crate) fn git_with_metadata(
// We expect to be able to parse any ref-hash, so we shouldn't have to know the repos hash here.
// With ref-table, the has is probably stored as part of the ref-db itself, so we can handle it from there.
// In other words, it's important not to fail on detached heads here because we guessed the hash kind wrongly.
let object_hash_should_not_matter_here = gix_hash::Kind::Sha1;
let refs = gix_ref::file::Store::at(
dot_git.as_ref().into(),
gix_ref::store::WriteReflog::Normal,
object_hash_should_not_matter_here,
false,
);
let refs = gix_ref::file::Store::at(dot_git.as_ref().into(), Default::default());
let head = refs.find_loose("HEAD")?;
if head.name.as_bstr() != "HEAD" {
return Err(crate::is_git::Error::MisplacedHead {
Expand Down
10 changes: 5 additions & 5 deletions gix-features/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ progress-unit-human-numbers = ["prodash?/unit-human"]
progress-unit-bytes = ["dep:bytesize", "prodash?/unit-bytes"]

## If set, walkdir iterators will be multi-threaded.
fs-walkdir-parallel = [ "dep:jwalk", "dep:gix-utils" ]
fs-walkdir-parallel = ["dep:jwalk", "dep:gix-utils"]

## Provide utilities suitable for working with the `std::fs::read_dir()`.
fs-read-dir = ["dep:gix-utils"]
Expand All @@ -34,18 +34,18 @@ fs-read-dir = ["dep:gix-utils"]
##
## Note that this may have overhead as well, thus instrumentations should be used stategically, only providing coarse tracing by default and adding details
## only where needed while marking them with the appropriate level.
tracing = [ "gix-trace/tracing" ]
tracing = ["gix-trace/tracing"]

## If enabled, detailed tracing is also emitted, which can greatly increase insights but at a cost.
tracing-detail = [ "gix-trace/tracing-detail" ]
tracing-detail = ["gix-trace/tracing-detail"]

## Use scoped threads and channels to parallelize common workloads on multiple objects. If enabled, it is used everywhere
## where it makes sense.
## As caches are likely to be used and instantiated per thread, more memory will be used on top of the costs for threads.
## The `threading` module will contain thread-safe primitives for shared ownership and mutation, otherwise these will be their single threaded counterparts.
## This way, single-threaded applications don't have to pay for threaded primitives.
parallel = ["dep:crossbeam-channel",
"dep:parking_lot"]
"dep:parking_lot"]
## If enabled, OnceCell will be made available for interior mutability either in sync or unsync forms.
once_cell = ["dep:once_cell"]
## Makes facilities of the `walkdir` crate partially available.
Expand Down Expand Up @@ -159,7 +159,7 @@ bstr = { version = "1.3.0", default-features = false }

# Assembly doesn't yet compile on MSVC on windows, but does on GNU, see https://github.com/RustCrypto/asm-hashes/issues/17
# At this time, only aarch64, x86 and x86_64 are supported.
[target.'cfg(all(any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64"), not(target_env = "msvc")))'.dependencies]
[target.'cfg(all(any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64"), not(target_os = "windows")))'.dependencies]
sha1 = { version = "0.10.0", optional = true, features = ["asm"] }

[package.metadata.docs.rs]
Expand Down
6 changes: 3 additions & 3 deletions gix-filter/tests/pipeline/convert_to_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn all_stages_mean_streaming_is_impossible() -> gix_testtools::Result {
Path::new("any.txt"),
&mut |path, attrs| {
cache
.at_entry(path, Some(false), &gix_object::find::Never)
.at_entry(path, None, &gix_object::find::Never)
.expect("cannot fail")
.matching_attributes(attrs);
},
Expand Down Expand Up @@ -82,7 +82,7 @@ fn only_driver_means_streaming_is_possible() -> gix_testtools::Result {
Path::new("subdir/doesnot/matter/any.txt"),
&mut |path, attrs| {
cache
.at_entry(path, Some(false), &gix_object::find::Never)
.at_entry(path, None, &gix_object::find::Never)
.expect("cannot fail")
.matching_attributes(attrs);
},
Expand Down Expand Up @@ -112,7 +112,7 @@ fn no_filter_means_reader_is_returned_unchanged() -> gix_testtools::Result {
Path::new("other.txt"),
&mut |path, attrs| {
cache
.at_entry(path, Some(false), &gix_object::find::Never)
.at_entry(path, None, &gix_object::find::Never)
.expect("cannot fail")
.matching_attributes(attrs);
},
Expand Down
6 changes: 3 additions & 3 deletions gix-filter/tests/pipeline/convert_to_worktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn all_stages() -> gix_testtools::Result {
"any.txt".into(),
&mut |path, attrs| {
cache
.at_entry(path, Some(false), &gix_object::find::Never)
.at_entry(path, None, &gix_object::find::Never)
.expect("cannot fail")
.matching_attributes(attrs);
},
Expand Down Expand Up @@ -54,7 +54,7 @@ fn all_stages_no_filter() -> gix_testtools::Result {
"other.txt".into(),
&mut |path, attrs| {
cache
.at_entry(path, Some(false), &gix_object::find::Never)
.at_entry(path, None, &gix_object::find::Never)
.expect("cannot fail")
.matching_attributes(attrs);
},
Expand Down Expand Up @@ -86,7 +86,7 @@ fn no_filter() -> gix_testtools::Result {
"other.txt".into(),
&mut |path, attrs| {
cache
.at_entry(path, Some(false), &gix_object::find::Never)
.at_entry(path, None, &gix_object::find::Never)
.expect("cannot fail")
.matching_attributes(attrs);
},
Expand Down
Loading

0 comments on commit 79dce79

Please sign in to comment.