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

template: add "empty" template item

This commit is contained in:
Samuel Tardieu 2023-01-14 11:43:23 +01:00
parent 665f7c5917
commit f563e550c4
3 changed files with 16 additions and 1 deletions

View file

@ -46,6 +46,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
e.g. `color.error = { bg = "red", bold = true, underline = true }` in your
`~/.jjconfig.toml`.
* The `empty` condition in templates is true when the commit makes no change to
the three compared to its parents.
### Fixed bugs
* When sharing the working copy with a Git repo, we used to forget to export

View file

@ -25,7 +25,7 @@ use crate::formatter::PlainTextFormatter;
use crate::templater::{
AuthorProperty, BranchProperty, ChangeIdProperty, CommitIdKeyword, CommitterProperty,
ConditionalTemplate, ConflictProperty, ConstantTemplateProperty, DescriptionProperty,
DivergentProperty, DynamicLabelTemplate, GitRefsProperty, IsGitHeadProperty,
DivergentProperty, DynamicLabelTemplate, EmptyProperty, GitRefsProperty, IsGitHeadProperty,
IsWorkingCopyProperty, LabelTemplate, ListTemplate, LiteralTemplate, SignatureTimestamp,
StringPropertyTemplate, TagProperty, Template, TemplateFunction, TemplateProperty,
WorkingCopiesProperty,
@ -316,6 +316,7 @@ fn parse_commit_keyword<'a>(
"is_git_head" => Property::Boolean(Box::new(IsGitHeadProperty::new(repo))),
"divergent" => Property::Boolean(Box::new(DivergentProperty::new(repo))),
"conflict" => Property::Boolean(Box::new(ConflictProperty)),
"empty" => Property::Boolean(Box::new(EmptyProperty { repo })),
name => panic!("unexpected identifier: {name}"),
};
PropertyAndLabels(property, vec![pair.as_str().to_string()])

View file

@ -23,6 +23,7 @@ use jujutsu_lib::commit::Commit;
use jujutsu_lib::op_store::WorkspaceId;
use jujutsu_lib::repo::RepoRef;
use jujutsu_lib::revset::RevsetExpression;
use jujutsu_lib::rewrite::merge_commit_trees;
use crate::formatter::Formatter;
@ -440,3 +441,13 @@ impl TemplateProperty<Signature, Timestamp> for SignatureTimestamp {
context.timestamp.clone()
}
}
pub struct EmptyProperty<'a> {
pub repo: RepoRef<'a>,
}
impl TemplateProperty<Commit, bool> for EmptyProperty<'_> {
fn extract(&self, context: &Commit) -> bool {
context.tree().id() == merge_commit_trees(self.repo, &context.parents()).id()
}
}