diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 7d7bad3c0..ecff2d720 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -67,6 +67,13 @@ pub enum RepoRef<'a> { } impl<'a> RepoRef<'a> { + pub fn base_repo(&self) -> &ReadonlyRepo { + match self { + RepoRef::Readonly(repo) => repo, + RepoRef::Mutable(repo) => repo.base_repo.as_ref(), + } + } + pub fn store(&self) -> &Arc { match self { RepoRef::Readonly(repo) => repo.store(), diff --git a/src/commands.rs b/src/commands.rs index cbe259623..52acb3680 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -2195,6 +2195,7 @@ fn log_template(settings: &UserSettings) -> String { " " label("timestamp", author.timestamp()) " " branches " " tags + if(is_git_head, label("git_head", " HEAD@git")) if(divergent, label("divergent", " divergent")) if(conflict, label("conflict", " conflict")) "\n" diff --git a/src/formatter.rs b/src/formatter.rs index 31a2f0047..442905b94 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -92,6 +92,7 @@ fn config_colors(user_settings: &UserSettings) -> HashMap { result.insert(String::from("branches"), String::from("magenta")); result.insert(String::from("tags"), String::from("magenta")); result.insert(String::from("git_refs"), String::from("magenta")); + result.insert(String::from("git_head"), String::from("magenta")); result.insert(String::from("divergent"), String::from("red")); result.insert(String::from("conflict"), String::from("red")); diff --git a/src/template_parser.rs b/src/template_parser.rs index e06657303..12e5270a7 100644 --- a/src/template_parser.rs +++ b/src/template_parser.rs @@ -25,9 +25,9 @@ use crate::formatter::PlainTextFormatter; use crate::templater::{ AuthorProperty, BranchProperty, ChangeIdProperty, CommitIdKeyword, CommitterProperty, ConditionalTemplate, ConflictProperty, ConstantTemplateProperty, CurrentCheckoutProperty, - DescriptionProperty, DivergentProperty, DynamicLabelTemplate, GitRefsProperty, LabelTemplate, - ListTemplate, LiteralTemplate, OpenProperty, StringPropertyTemplate, TagProperty, Template, - TemplateFunction, TemplateProperty, + DescriptionProperty, DivergentProperty, DynamicLabelTemplate, GitRefsProperty, + IsGitHeadProperty, LabelTemplate, ListTemplate, LiteralTemplate, OpenProperty, + StringPropertyTemplate, TagProperty, Template, TemplateFunction, TemplateProperty, }; #[derive(Parser)] @@ -242,6 +242,7 @@ fn parse_commit_keyword<'a>(repo: RepoRef<'a>, pair: Pair) -> (Property<'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))), "divergent" => Property::Boolean(Box::new(DivergentProperty::new(repo))), "conflict" => Property::Boolean(Box::new(ConflictProperty)), name => panic!("unexpected identifier: {}", name), diff --git a/src/templater.rs b/src/templater.rs index c47170c60..b1f79116a 100644 --- a/src/templater.rs +++ b/src/templater.rs @@ -288,6 +288,22 @@ impl TemplateProperty for GitRefsProperty<'_> { } } +pub struct IsGitHeadProperty<'a> { + repo: RepoRef<'a>, +} + +impl<'a> IsGitHeadProperty<'a> { + pub fn new(repo: RepoRef<'a>) -> Self { + Self { repo } + } +} + +impl TemplateProperty for IsGitHeadProperty<'_> { + fn extract(&self, context: &Commit) -> bool { + self.repo.view().git_head().as_ref() == Some(context.id()) + } +} + pub struct DivergentProperty { divergent_changes: HashSet, }