templater: replace is_git_head keyword by git_head keyword

I'm about to make it possible for `HEAD@git` to be conflicted. For
that, we need to be able to include the trailing `?`. This patch
prepares for that.
This commit is contained in:
Martin von Zweigbergk 2022-12-17 10:17:50 -08:00 committed by Martin von Zweigbergk
parent 23fc849574
commit 6cf7d98465
4 changed files with 15 additions and 11 deletions

View file

@ -1391,7 +1391,7 @@ fn log_template(settings: &UserSettings) -> String {
if(branches, " " branches)
if(tags, " " tags)
if(working_copies, " " working_copies)
if(is_git_head, label("git_head", " HEAD@git"))
if(git_head, " " git_head)
" " commit_id.{prefix_format}
if(conflict, label("conflict", " conflict"))
"\n"

View file

@ -26,8 +26,8 @@ use crate::templater::{
AuthorProperty, BranchProperty, ChangeIdProperty, CommitIdProperty, CommitOrChangeId,
CommitOrChangeIdShort, CommitOrChangeIdShortPrefixAndBrackets, CommitterProperty,
ConditionalTemplate, ConflictProperty, DescriptionProperty, DivergentProperty,
DynamicLabelTemplate, EmptyProperty, FormattablePropertyTemplate, GitRefsProperty,
IsGitHeadProperty, IsWorkingCopyProperty, LabelTemplate, ListTemplate, Literal,
DynamicLabelTemplate, EmptyProperty, FormattablePropertyTemplate, GitHeadProperty,
GitRefsProperty, IsWorkingCopyProperty, LabelTemplate, ListTemplate, Literal,
SignatureTimestamp, TagProperty, Template, TemplateFunction, TemplateProperty,
WorkingCopiesProperty,
};
@ -239,7 +239,7 @@ fn parse_commit_keyword<'a>(
"branches" => Property::String(Box::new(BranchProperty { repo })),
"tags" => Property::String(Box::new(TagProperty { repo })),
"git_refs" => Property::String(Box::new(GitRefsProperty { repo })),
"is_git_head" => Property::Boolean(Box::new(IsGitHeadProperty::new(repo))),
"git_head" => Property::String(Box::new(GitHeadProperty::new(repo))),
"divergent" => Property::Boolean(Box::new(DivergentProperty::new(repo))),
"conflict" => Property::Boolean(Box::new(ConflictProperty)),
"empty" => Property::Boolean(Box::new(EmptyProperty { repo })),

View file

@ -348,21 +348,25 @@ impl TemplateProperty<Commit> for GitRefsProperty<'_> {
}
}
pub struct IsGitHeadProperty<'a> {
pub struct GitHeadProperty<'a> {
repo: RepoRef<'a>,
}
impl<'a> IsGitHeadProperty<'a> {
impl<'a> GitHeadProperty<'a> {
pub fn new(repo: RepoRef<'a>) -> Self {
Self { repo }
}
}
impl TemplateProperty<Commit> for IsGitHeadProperty<'_> {
type Output = bool;
impl TemplateProperty<Commit> for GitHeadProperty<'_> {
type Output = String;
fn extract(&self, context: &Commit) -> Self::Output {
self.repo.view().git_head().as_ref() == Some(context.id())
fn extract(&self, context: &Commit) -> String {
if self.repo.view().git_head().as_ref() == Some(context.id()) {
"HEAD@git".to_string()
} else {
"".to_string()
}
}
}

View file

@ -173,7 +173,7 @@ fn test_log_git_head() {
insta::assert_snapshot!(stdout, @r###"
@ 8[e4fac809c] test.user@example.com 2001-02-03 04:05:09.000 +07:00 5[0aaf4754c]
| initial
o 9[a45c67d3e] test.user@example.com 2001-02-03 04:05:07.000 +07:00 master HEAD@git 23[0dd059e1]
o 9[a45c67d3e] test.user@example.com 2001-02-03 04:05:07.000 +07:00 master HEAD@git 23[0dd059e1]
| (empty) (no description set)
o 0[000000000] 1970-01-01 00:00:00.000 +00:00 0[000000000]
(empty) (no description set)