forked from mirrors/jj
templater: inline TemplateFormatter into write_commit_summary()
It's not used extensively, and I don't think this abstraction is useful for the moment.
This commit is contained in:
parent
e716168368
commit
d2b8240648
2 changed files with 1 additions and 24 deletions
|
@ -58,7 +58,6 @@ use tracing_subscriber::prelude::*;
|
|||
use crate::config::{FullCommandArgs, LayeredConfigs};
|
||||
use crate::formatter::{Formatter, PlainTextFormatter};
|
||||
use crate::merge_tools::{ConflictResolveError, DiffEditError};
|
||||
use crate::templater::TemplateFormatter;
|
||||
use crate::ui::{ColorChoice, Ui};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -1389,9 +1388,7 @@ pub fn write_commit_summary(
|
|||
.unwrap_or_else(|_| String::from(r#"commit_id.short() " " description.first_line()"#));
|
||||
let template =
|
||||
crate::template_parser::parse_commit_template(repo, workspace_id, &template_string);
|
||||
let mut template_writer = TemplateFormatter::new(template, formatter);
|
||||
template_writer.format(commit)?;
|
||||
Ok(())
|
||||
template.format(commit, formatter)
|
||||
}
|
||||
|
||||
pub fn write_config_entry(
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::borrow::BorrowMut;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::io;
|
||||
use std::ops::AddAssign;
|
||||
|
@ -31,25 +30,6 @@ pub trait Template<C> {
|
|||
fn format(&self, context: &C, formatter: &mut dyn Formatter) -> io::Result<()>;
|
||||
}
|
||||
|
||||
// TODO: Extract a trait for this type?
|
||||
pub struct TemplateFormatter<'f, 't: 'f, C> {
|
||||
template: Box<dyn Template<C> + 't>,
|
||||
formatter: &'f mut dyn Formatter,
|
||||
}
|
||||
|
||||
impl<'f, 't: 'f, C> TemplateFormatter<'f, 't, C> {
|
||||
pub fn new(template: Box<dyn Template<C> + 't>, formatter: &'f mut dyn Formatter) -> Self {
|
||||
TemplateFormatter {
|
||||
template,
|
||||
formatter,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn format<'c, 'a: 'c>(&'a mut self, context: &'c C) -> io::Result<()> {
|
||||
self.template.format(context, self.formatter.borrow_mut())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LiteralTemplate(pub String);
|
||||
|
||||
impl<C> Template<C> for LiteralTemplate {
|
||||
|
|
Loading…
Reference in a new issue