Skip to content

Commit

Permalink
Use Defaults::from_environment() when parsing pathspecs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 17, 2023
1 parent fb9d4db commit 2a99034
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ tracing = { version = "0.1.37", optional = true }
owo-colors = "3.5.0"
tabled = { version = "0.10.0", default-features = false }

once_cell = "1.18.0"
document-features = { version = "0.2.0", optional = true }

[profile.dev.package]
Expand Down
18 changes: 9 additions & 9 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,14 +1030,13 @@ pub fn main() -> Result<()> {
core::repository::attributes::query(
repository(Mode::Strict)?,
if pathspec.is_empty() {
Box::new(stdin_or_bail()?.byte_lines().filter_map(Result::ok).filter_map(|line| {
gix::pathspec::parse(
line.as_bstr(),
// TODO(pathspec): use `repo` actual global defaults when available (see following as well)
Default::default(),
)
.ok()
})) as Box<dyn Iterator<Item = gix::pathspec::Pattern>>
let defaults = gix::pathspec::Defaults::from_environment()?;
Box::new(
stdin_or_bail()?
.byte_lines()
.filter_map(Result::ok)
.filter_map(move |line| gix::pathspec::parse(line.as_bstr(), defaults).ok()),
) as Box<dyn Iterator<Item = gix::pathspec::Pattern>>
} else {
Box::new(pathspec.into_iter())
},
Expand Down Expand Up @@ -1089,11 +1088,12 @@ pub fn main() -> Result<()> {
core::repository::exclude::query(
repository(Mode::Strict)?,
if pathspec.is_empty() {
let defaults = gix::pathspec::Defaults::from_environment()?;
Box::new(
stdin_or_bail()?
.byte_lines()
.filter_map(Result::ok)
.filter_map(|line| gix::pathspec::parse(&line, Default::default()).ok()),
.filter_map(move |line| gix::pathspec::parse(&line, defaults).ok()),
) as Box<dyn Iterator<Item = gix::pathspec::Pattern>>
} else {
Box::new(pathspec.into_iter())
Expand Down
10 changes: 4 additions & 6 deletions src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,19 +348,17 @@ mod clap {
#[derive(Clone)]
pub struct AsPathSpec;

static PATHSPEC_DEFAULTS: once_cell::sync::Lazy<gix::pathspec::Defaults> =
once_cell::sync::Lazy::new(|| gix::pathspec::Defaults::from_environment().unwrap_or_default());

impl TypedValueParser for AsPathSpec {
type Value = gix::pathspec::Pattern;

fn parse_ref(&self, cmd: &Command, arg: Option<&Arg>, value: &OsStr) -> Result<Self::Value, Error> {
OsStringValueParser::new()
.try_map(|arg| {
let arg: &std::path::Path = arg.as_os_str().as_ref();
gix::pathspec::parse(
gix::path::into_bstr(arg).as_ref(),
// TODO(pathspec): it *should* be possible to obtain these defaults from the environment and then act correctly.
// gix should
Default::default(),
)
gix::pathspec::parse(gix::path::into_bstr(arg).as_ref(), *PATHSPEC_DEFAULTS)
})
.parse_ref(cmd, arg, value)
}
Expand Down

0 comments on commit 2a99034

Please sign in to comment.