Make get_env_var return a reference to a Value (#13987)

# Description
Title says it all, changes `EngineState::get_env_var` to return a
`Option<&'a Value>` instead of an owned `Option<Value>`. This avoids
some unnecessary clones.

I also made a similar change to the `PluginExecutionContext` trait.
This commit is contained in:
Ian Manske
2024-10-02 04:05:48 -07:00
committed by GitHub
parent f03ba6793e
commit 157494e803
17 changed files with 74 additions and 51 deletions

View File

@ -107,7 +107,7 @@ impl Command for Cd {
// Set OLDPWD.
// We're using `Stack::get_env_var()` instead of `EngineState::cwd()` to avoid a conversion roundtrip.
if let Some(oldpwd) = stack.get_env_var(engine_state, "PWD") {
stack.add_env_var("OLDPWD".into(), oldpwd)
stack.add_env_var("OLDPWD".into(), oldpwd.clone())
}
match have_permission(&path) {

View File

@ -314,7 +314,7 @@ fn send_form_request(
Value::List { ref vals, .. } => {
if vals.len() % 2 != 0 {
return Err(ShellErrorOrRequestError::ShellError(ShellError::IncorrectValue {
msg: "Body type 'list' for form requests requires paired values. E.g.: [foo, 10]".into(),
msg: "Body type 'list' for form requests requires paired values. E.g.: [foo, 10]".into(),
val_span: body.span(),
call_span: span,
}));
@ -901,6 +901,7 @@ fn retrieve_http_proxy_from_env(engine_state: &EngineState, stack: &mut Stack) -
.or(stack.get_env_var(engine_state, "https_proxy"))
.or(stack.get_env_var(engine_state, "HTTPS_PROXY"))
.or(stack.get_env_var(engine_state, "ALL_PROXY"))
.cloned()
.and_then(|proxy| proxy.coerce_into_string().ok())
}

View File

@ -69,7 +69,7 @@ prints out the list properly."#
let icons_param: bool = call.has_flag(engine_state, stack, "icons")?;
let config = &stack.get_config(engine_state);
let env_str = match stack.get_env_var(engine_state, "LS_COLORS") {
Some(v) => Some(env_to_string("LS_COLORS", &v, engine_state, stack)?),
Some(v) => Some(env_to_string("LS_COLORS", v, engine_state, stack)?),
None => None,
};

View File

@ -623,7 +623,7 @@ fn handle_row_stream(
let ls_colors_env_str = match input.stack.get_env_var(input.engine_state, "LS_COLORS") {
Some(v) => Some(env_to_string(
"LS_COLORS",
&v,
v,
input.engine_state,
input.stack,
)?),