mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-10 22:39:32 +00:00
cli_util: add tx.commit_summary_template() and related helper functions
These functions mirror the ones in WorkspaceCommandHelper. I'm not sure if all of them will have to be public, but parse_commit_template() might be useful in order to implement description template.
This commit is contained in:
parent
b762dd55cd
commit
8df7857706
1 changed files with 27 additions and 11 deletions
|
@ -1659,27 +1659,43 @@ impl WorkspaceCommandTransaction<'_> {
|
||||||
formatter: &mut dyn Formatter,
|
formatter: &mut dyn Formatter,
|
||||||
commit: &Commit,
|
commit: &Commit,
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
|
self.commit_summary_template().format(commit, formatter)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Template for one-line summary of a commit within transaction.
|
||||||
|
pub fn commit_summary_template(&self) -> TemplateRenderer<'_, Commit> {
|
||||||
|
self.parse_commit_template(&self.helper.commit_summary_template_text)
|
||||||
|
.expect("parse error should be confined by WorkspaceCommandHelper::new()")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates commit template language environment capturing the current
|
||||||
|
/// transaction state.
|
||||||
|
pub fn commit_template_language(&self) -> CommitTemplateLanguage<'_> {
|
||||||
let id_prefix_context = self
|
let id_prefix_context = self
|
||||||
.id_prefix_context
|
.id_prefix_context
|
||||||
.get_or_try_init(|| self.helper.new_id_prefix_context())
|
.get_or_try_init(|| self.helper.new_id_prefix_context())
|
||||||
.expect("parse error should be confined by WorkspaceCommandHelper::new()");
|
.expect("parse error should be confined by WorkspaceCommandHelper::new()");
|
||||||
let language = CommitTemplateLanguage::new(
|
CommitTemplateLanguage::new(
|
||||||
self.tx.repo(),
|
self.tx.repo(),
|
||||||
&self.helper.path_converter,
|
&self.helper.path_converter,
|
||||||
self.helper.workspace_id(),
|
self.helper.workspace_id(),
|
||||||
self.helper.revset_parse_context(),
|
self.helper.revset_parse_context(),
|
||||||
id_prefix_context,
|
id_prefix_context,
|
||||||
&self.helper.commit_template_extensions,
|
&self.helper.commit_template_extensions,
|
||||||
);
|
)
|
||||||
let template = self
|
}
|
||||||
.helper
|
|
||||||
.parse_template(
|
/// Parses commit template with the current transaction state.
|
||||||
|
pub fn parse_commit_template(
|
||||||
|
&self,
|
||||||
|
template_text: &str,
|
||||||
|
) -> Result<TemplateRenderer<'_, Commit>, CommandError> {
|
||||||
|
let language = self.commit_template_language();
|
||||||
|
self.helper.parse_template(
|
||||||
&language,
|
&language,
|
||||||
&self.helper.commit_summary_template_text,
|
template_text,
|
||||||
CommitTemplateLanguage::wrap_commit,
|
CommitTemplateLanguage::wrap_commit,
|
||||||
)
|
)
|
||||||
.expect("parse error should be confined by WorkspaceCommandHelper::new()");
|
|
||||||
template.format(commit, formatter)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finish(self, ui: &mut Ui, description: impl Into<String>) -> Result<(), CommandError> {
|
pub fn finish(self, ui: &mut Ui, description: impl Into<String>) -> Result<(), CommandError> {
|
||||||
|
|
Loading…
Reference in a new issue