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

cli: have complete_newline() return String instead of mutating

String -> String function is more convenient in one liner, and it's unlikely
we'll use this function in hot loop.
This commit is contained in:
Yuya Nishihara 2023-01-31 18:55:15 +09:00
parent e4cb1afd61
commit 12d8c4ef01
2 changed files with 6 additions and 6 deletions

View file

@ -1655,9 +1655,8 @@ impl DescriptionArg {
}
impl From<String> for DescriptionArg {
fn from(mut s: String) -> Self {
complete_newline(&mut s);
DescriptionArg(s)
fn from(s: String) -> Self {
DescriptionArg(complete_newline(s))
}
}
@ -1673,10 +1672,12 @@ impl AsRef<str> for DescriptionArg {
}
}
pub fn complete_newline(s: &mut String) {
pub fn complete_newline(s: impl Into<String>) -> String {
let mut s = s.into();
if !s.is_empty() && !s.ends_with('\n') {
s.push('\n');
}
s
}
#[derive(Clone, Debug)]

View file

@ -1751,8 +1751,7 @@ fn edit_description(
.filter(|line| !line.starts_with("JJ: "))
.join("\n");
description.truncate(description.trim_end_matches('\n').len());
cli_util::complete_newline(&mut description);
Ok(description)
Ok(cli_util::complete_newline(description))
}
fn cmd_describe(