ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: rename interpolate_mergetool_filename_patterns(), inline caller

I'll add string interpolation support to edit-args.
This commit is contained in:
Yuya Nishihara 2023-02-06 19:36:34 +09:00
parent baa67fe1db
commit 449e84d7ea

View file

@ -236,9 +236,8 @@ pub fn run_mergetool(
}) })
.try_collect()?; .try_collect()?;
let args = interpolate_mergetool_filename_patterns(&editor.merge_args, &paths);
let mut cmd = Command::new(&editor.program); let mut cmd = Command::new(&editor.program);
cmd.args(args); cmd.args(interpolate_variables(&editor.merge_args, &paths));
tracing::debug!(?cmd, "Invoking the external merge tool:"); tracing::debug!(?cmd, "Invoking the external merge tool:");
let exit_status = cmd let exit_status = cmd
.status() .status()
@ -282,17 +281,16 @@ pub fn run_mergetool(
Ok(tree_builder.write_tree()) Ok(tree_builder.write_tree())
} }
fn interpolate_mergetool_filename_patterns<V: AsRef<str>>( fn interpolate_variables<V: AsRef<str>>(
merge_args: &[String], args: &[String],
paths: &HashMap<&str, V>, variables: &HashMap<&str, V>,
) -> Vec<String> { ) -> Vec<String> {
merge_args args.iter()
.iter()
.map(|arg| { .map(|arg| {
// TODO: Match all instances of `\$\w+` pattern and replace them // TODO: Match all instances of `\$\w+` pattern and replace them
// so that portions of args can be replaced, and so that file paths // so that portions of args can be replaced, and so that file paths
// that include the '$' character are processed correctly. // that include the '$' character are processed correctly.
if let Some(subst) = arg.strip_prefix('$').and_then(|p| paths.get(p)) { if let Some(subst) = arg.strip_prefix('$').and_then(|p| variables.get(p)) {
subst.as_ref().to_owned() subst.as_ref().to_owned()
} else { } else {
arg.clone() arg.clone()