From bcece02084ab90ab3074fe1988ef804d77edab6a Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 2 Feb 2022 17:00:05 -0800 Subject: [PATCH] cli: indicate each workspace's checkout in log (#13) It seems helpful to show in the log output which commit is checked out in which workspace, so let's try that. I made it only show the information if there are multiple checkouts for now. --- src/commands.rs | 1 + src/formatter.rs | 5 +++++ src/template_parser.rs | 9 +++++---- src/templater.rs | 20 ++++++++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index c7f30dcc5..00a92ec9a 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -2549,6 +2549,7 @@ fn log_template(settings: &UserSettings) -> String { " " label("timestamp", author.timestamp()) " " branches " " tags + " " checkouts if(is_git_head, label("git_head", " HEAD@git")) if(divergent, label("divergent", " divergent")) if(conflict, label("conflict", " conflict")) diff --git a/src/formatter.rs b/src/formatter.rs index d4cc9f08d..a3884327b 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -88,6 +88,7 @@ fn config_colors(user_settings: &UserSettings) -> HashMap { result.insert(String::from("author timestamp"), String::from("cyan")); result.insert(String::from("committer"), String::from("yellow")); result.insert(String::from("committer timestamp"), String::from("cyan")); + result.insert(String::from("checkouts"), String::from("magenta")); result.insert(String::from("branch"), String::from("magenta")); result.insert(String::from("branches"), String::from("magenta")); result.insert(String::from("tags"), String::from("magenta")); @@ -128,6 +129,10 @@ fn config_colors(user_settings: &UserSettings) -> HashMap { String::from("checkout committer timestamp"), String::from("bright cyan"), ); + result.insert( + String::from("checkout checkouts"), + String::from("bright magenta"), + ); result.insert( String::from("checkout branch"), String::from("bright magenta"), diff --git a/src/template_parser.rs b/src/template_parser.rs index 2db330d80..6a9f87e5d 100644 --- a/src/template_parser.rs +++ b/src/template_parser.rs @@ -24,10 +24,10 @@ use pest::Parser; use crate::formatter::PlainTextFormatter; use crate::templater::{ - AuthorProperty, BranchProperty, ChangeIdProperty, CommitIdKeyword, CommitterProperty, - ConditionalTemplate, ConflictProperty, ConstantTemplateProperty, CurrentCheckoutProperty, - DescriptionProperty, DivergentProperty, DynamicLabelTemplate, GitRefsProperty, - IsGitHeadProperty, LabelTemplate, ListTemplate, LiteralTemplate, OpenProperty, + AuthorProperty, BranchProperty, ChangeIdProperty, CheckoutsProperty, CommitIdKeyword, + CommitterProperty, ConditionalTemplate, ConflictProperty, ConstantTemplateProperty, + CurrentCheckoutProperty, DescriptionProperty, DivergentProperty, DynamicLabelTemplate, + GitRefsProperty, IsGitHeadProperty, LabelTemplate, ListTemplate, LiteralTemplate, OpenProperty, StringPropertyTemplate, TagProperty, Template, TemplateFunction, TemplateProperty, }; @@ -243,6 +243,7 @@ fn parse_commit_keyword<'a>( "author" => Property::Signature(Box::new(AuthorProperty)), "committer" => Property::Signature(Box::new(CommitterProperty)), "open" => Property::Boolean(Box::new(OpenProperty)), + "checkouts" => Property::String(Box::new(CheckoutsProperty { repo })), "current_checkout" => Property::Boolean(Box::new(CurrentCheckoutProperty { repo, workspace_id: workspace_id.clone(), diff --git a/src/templater.rs b/src/templater.rs index 471ba810e..eeba157e9 100644 --- a/src/templater.rs +++ b/src/templater.rs @@ -205,6 +205,26 @@ impl<'r> TemplateProperty for OpenProperty { } } +pub struct CheckoutsProperty<'a> { + pub repo: RepoRef<'a>, +} + +impl TemplateProperty for CheckoutsProperty<'_> { + fn extract(&self, context: &Commit) -> String { + let checkouts = self.repo.view().checkouts(); + if checkouts.len() <= 1 { + return "".to_string(); + } + let mut names = vec![]; + for (workspace_id, checkout_id) in checkouts.iter().sorted() { + if checkout_id == context.id() { + names.push(format!("{}@", workspace_id.as_str())); + } + } + names.join(" ") + } +} + pub struct CurrentCheckoutProperty<'a> { pub repo: RepoRef<'a>, pub workspace_id: WorkspaceId,