From a565e2bff784d17f695b4e12c7067183ba145414 Mon Sep 17 00:00:00 2001 From: e-q Date: Mon, 20 May 2024 11:35:48 -0400 Subject: [PATCH 1/3] smartlog: replace `--reverse` flag with config opt --- git-branchless-lib/src/core/config.rs | 7 +++++++ git-branchless-opts/src/lib.rs | 5 ----- git-branchless-smartlog/src/lib.rs | 12 +++--------- git-branchless-smartlog/tests/test_smartlog.rs | 8 +++++--- git-branchless/tests/test_init.rs | 4 ++-- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/git-branchless-lib/src/core/config.rs b/git-branchless-lib/src/core/config.rs index 69a80c069..4fe072c7a 100644 --- a/git-branchless-lib/src/core/config.rs +++ b/git-branchless-lib/src/core/config.rs @@ -108,6 +108,13 @@ pub fn get_smartlog_default_revset(repo: &Repo) -> eyre::Result { }) } +/// Whether to reverse the smartlog direction by default +#[instrument] +pub fn get_smartlog_reverse(repo: &Repo) -> eyre::Result { + repo.get_readonly_config()? + .get_or("branchless.smartlog.reverse", false) +} + /// Get the default comment character. #[instrument] pub fn get_comment_char(repo: &Repo) -> eyre::Result { diff --git a/git-branchless-opts/src/lib.rs b/git-branchless-opts/src/lib.rs index 131eea0e1..60aa4a9a9 100644 --- a/git-branchless-opts/src/lib.rs +++ b/git-branchless-opts/src/lib.rs @@ -340,11 +340,6 @@ pub struct SmartlogArgs { #[clap(value_parser)] pub revset: Option, - /// Print the smartlog in the opposite of the usual order, with the latest - /// commits first. - #[clap(long)] - pub reverse: bool, - /// Don't automatically add HEAD and the main branch to the list of commits /// to present. They will still be added if included in the revset. #[clap(long)] diff --git a/git-branchless-smartlog/src/lib.rs b/git-branchless-smartlog/src/lib.rs index e3b3bdc3f..7c251906f 100644 --- a/git-branchless-smartlog/src/lib.rs +++ b/git-branchless-smartlog/src/lib.rs @@ -19,8 +19,8 @@ use std::time::SystemTime; use git_branchless_invoke::CommandContext; use git_branchless_opts::{Revset, SmartlogArgs}; use lib::core::config::{ - get_hint_enabled, get_hint_string, get_smartlog_default_revset, print_hint_suppression_notice, - Hint, + get_hint_enabled, get_hint_string, get_smartlog_default_revset, get_smartlog_reverse, + print_hint_suppression_notice, Hint, }; use lib::core::repo_ext::RepoExt; use lib::core::rewrite::find_rewrite_target; @@ -747,10 +747,6 @@ mod render { /// The options to use when resolving the revset. pub resolve_revset_options: ResolveRevsetOptions, - /// Reverse the ordering of items in the smartlog output, list the most - /// recent commits first. - pub reverse: bool, - /// Normally HEAD and the main branch are included. Set this to exclude them. pub exact: bool, } @@ -767,7 +763,6 @@ pub fn smartlog( event_id, revset, resolve_revset_options, - reverse, exact, } = options; @@ -825,6 +820,7 @@ pub fn smartlog( exact, )?; + let reverse = get_smartlog_reverse(&repo)?; let mut lines = render_graph( &effects.reverse_order(reverse), &repo, @@ -914,7 +910,6 @@ pub fn command_main(ctx: CommandContext, args: SmartlogArgs) -> EyreExitOr<()> { event_id, revset, resolve_revset_options, - reverse, exact, } = args; @@ -925,7 +920,6 @@ pub fn command_main(ctx: CommandContext, args: SmartlogArgs) -> EyreExitOr<()> { event_id, revset, resolve_revset_options, - reverse, exact, }, ) diff --git a/git-branchless-smartlog/tests/test_smartlog.rs b/git-branchless-smartlog/tests/test_smartlog.rs index 2b53bd6e3..505cc82f7 100644 --- a/git-branchless-smartlog/tests/test_smartlog.rs +++ b/git-branchless-smartlog/tests/test_smartlog.rs @@ -183,6 +183,7 @@ fn test_merge_commit_reverse_order() -> eyre::Result<()> { let git = make_git()?; git.init_repo()?; + git.run(&["config", "branchless.smartlog.reverse", "true"])?; git.run(&["checkout", "-b", "test1", "master"])?; git.commit_file("test1", 1)?; git.run(&["checkout", "-b", "test2and3", "master"])?; @@ -196,7 +197,7 @@ fn test_merge_commit_reverse_order() -> eyre::Result<()> { }, )?; - let (stdout, _) = git.branchless("smartlog", &["--reverse"])?; + let (stdout, _) = git.branchless("smartlog", &[])?; insta::assert_snapshot!(stdout, @r###" @ fa4e4e1 (> test2and3) Merge branch 'test1' into test2and3 |\ @@ -499,7 +500,7 @@ fn test_smartlog_hint_abandoned_except_current_commit() -> eyre::Result<()> { Ok(()) } -/// When --reverse is specified hints still appear at the end of output +/// When branchless.smartlog.reverse is `true`, hints still appear at the end of output #[test] fn test_smartlog_hint_abandoned_reverse_order() -> eyre::Result<()> { let git = make_git()?; @@ -508,6 +509,7 @@ fn test_smartlog_hint_abandoned_reverse_order() -> eyre::Result<()> { return Ok(()); } git.init_repo()?; + git.run(&["config", "branchless.smartlog.reverse", "true"])?; git.detach_head()?; git.commit_file("test1", 1)?; @@ -515,7 +517,7 @@ fn test_smartlog_hint_abandoned_reverse_order() -> eyre::Result<()> { git.run(&["checkout", "HEAD^"])?; git.run(&["commit", "--amend", "-m", "amended test1"])?; - let (stdout, _) = git.branchless("smartlog", &["--reverse"])?; + let (stdout, _) = git.branchless("smartlog", &[])?; insta::assert_snapshot!(stdout, @r###" o 96d1c37 create test2.txt | diff --git a/git-branchless/tests/test_init.rs b/git-branchless/tests/test_init.rs index e8536a535..31d96cf07 100644 --- a/git-branchless/tests/test_init.rs +++ b/git-branchless/tests/test_init.rs @@ -316,9 +316,9 @@ fn test_main_branch_not_found_error_message() -> eyre::Result<()> { 0: branchless::core::eventlog::from_event_log_db with effects= repo=/.git/"> event_log_db=/.git/branchless/db.sqlite3")> at some/file/path.rs:123 - 1: git_branchless_smartlog::smartlog with effects= git_run_info= options=SmartlogOptions { event_id: None, revset: None, resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false }, reverse: false, exact: false } + 1: git_branchless_smartlog::smartlog with effects= git_run_info= options=SmartlogOptions { event_id: None, revset: None, resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false }, exact: false } at some/file/path.rs:123 - 2: git_branchless_smartlog::command_main with ctx=CommandContext { effects: , git_run_info: } args=SmartlogArgs { event_id: None, revset: None, reverse: false, exact: false, resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false } } + 2: git_branchless_smartlog::command_main with ctx=CommandContext { effects: , git_run_info: } args=SmartlogArgs { event_id: None, revset: None, exact: false, resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false } } at some/file/path.rs:123 Suggestion: From d88f75da839e188bdedd02261a5ccbb6b649f9c7 Mon Sep 17 00:00:00 2001 From: e-q Date: Tue, 28 May 2024 10:51:00 -0400 Subject: [PATCH 2/3] Restore `--reverse` flag with deprecation warning --- git-branchless-opts/src/lib.rs | 6 ++++++ git-branchless-smartlog/src/lib.rs | 27 ++++++++++++++++++++++++--- git-branchless/tests/test_init.rs | 4 ++-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/git-branchless-opts/src/lib.rs b/git-branchless-opts/src/lib.rs index 60aa4a9a9..1ed27995e 100644 --- a/git-branchless-opts/src/lib.rs +++ b/git-branchless-opts/src/lib.rs @@ -340,6 +340,12 @@ pub struct SmartlogArgs { #[clap(value_parser)] pub revset: Option, + /// (Deprecated) + /// Print the smartlog in the opposite of the usual order, with the latest + /// commits first. Can be configured via `branchless.smartlog.reverse`. + #[clap(long)] + pub reverse: bool, + /// Don't automatically add HEAD and the main branch to the list of commits /// to present. They will still be added if included in the revset. #[clap(long)] diff --git a/git-branchless-smartlog/src/lib.rs b/git-branchless-smartlog/src/lib.rs index 7c251906f..0677ac5e6 100644 --- a/git-branchless-smartlog/src/lib.rs +++ b/git-branchless-smartlog/src/lib.rs @@ -747,6 +747,11 @@ mod render { /// The options to use when resolving the revset. pub resolve_revset_options: ResolveRevsetOptions, + /// Deprecated + /// Reverse the ordering of items in the smartlog output, list the most + /// recent commits first. + pub reverse: bool, + /// Normally HEAD and the main branch are included. Set this to exclude them. pub exact: bool, } @@ -763,6 +768,7 @@ pub fn smartlog( event_id, revset, resolve_revset_options, + reverse, exact, } = options; @@ -820,9 +826,22 @@ pub fn smartlog( exact, )?; - let reverse = get_smartlog_reverse(&repo)?; + if reverse { + print!( + "\ +branchless: WARNING: The `--reverse` flag is deprecated. +branchless: Please use the `branchless.smartlog.reverse` configuration option. +" + ); + } + let reverse_cfg = get_smartlog_reverse(&repo)?; + let reverse_value = match (reverse_cfg, reverse) { + (.., true) => true, + _ => reverse_cfg, + }; + let mut lines = render_graph( - &effects.reverse_order(reverse), + &effects.reverse_order(reverse_value), &repo, &dag, &graph, @@ -845,7 +864,7 @@ pub fn smartlog( ], )? .into_iter(); - while let Some(line) = if reverse { + while let Some(line) = if reverse_value { lines.next_back() } else { lines.next() @@ -910,6 +929,7 @@ pub fn command_main(ctx: CommandContext, args: SmartlogArgs) -> EyreExitOr<()> { event_id, revset, resolve_revset_options, + reverse, exact, } = args; @@ -920,6 +940,7 @@ pub fn command_main(ctx: CommandContext, args: SmartlogArgs) -> EyreExitOr<()> { event_id, revset, resolve_revset_options, + reverse, exact, }, ) diff --git a/git-branchless/tests/test_init.rs b/git-branchless/tests/test_init.rs index 31d96cf07..e8536a535 100644 --- a/git-branchless/tests/test_init.rs +++ b/git-branchless/tests/test_init.rs @@ -316,9 +316,9 @@ fn test_main_branch_not_found_error_message() -> eyre::Result<()> { 0: branchless::core::eventlog::from_event_log_db with effects= repo=/.git/"> event_log_db=/.git/branchless/db.sqlite3")> at some/file/path.rs:123 - 1: git_branchless_smartlog::smartlog with effects= git_run_info= options=SmartlogOptions { event_id: None, revset: None, resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false }, exact: false } + 1: git_branchless_smartlog::smartlog with effects= git_run_info= options=SmartlogOptions { event_id: None, revset: None, resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false }, reverse: false, exact: false } at some/file/path.rs:123 - 2: git_branchless_smartlog::command_main with ctx=CommandContext { effects: , git_run_info: } args=SmartlogArgs { event_id: None, revset: None, exact: false, resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false } } + 2: git_branchless_smartlog::command_main with ctx=CommandContext { effects: , git_run_info: } args=SmartlogArgs { event_id: None, revset: None, reverse: false, exact: false, resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false } } at some/file/path.rs:123 Suggestion: From 0872e9aa2ed723abc1f4f00fd6f5fd7f364c8da8 Mon Sep 17 00:00:00 2001 From: e-q Date: Tue, 4 Jun 2024 14:14:01 -0400 Subject: [PATCH 3/3] Add reversed version of `commit_merge` glyph --- git-branchless-lib/src/core/formatting.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/git-branchless-lib/src/core/formatting.rs b/git-branchless-lib/src/core/formatting.rs index a228a0975..4da041a24 100644 --- a/git-branchless-lib/src/core/formatting.rs +++ b/git-branchless-lib/src/core/formatting.rs @@ -127,6 +127,10 @@ pub struct Glyphs { /// commit or merged from this parent commit. pub commit_merge: &'static str, + /// Alternative character for `commit_merge` when the smartlog orientation + /// is reversed. + pub commit_merge_rev: &'static str, + /// Character used to point to the currently-checked-out branch. pub branch_arrow: &'static str, @@ -179,6 +183,7 @@ impl Glyphs { commit_main_obsolete_head: "%", commit_omitted: "#", commit_merge: "&", + commit_merge_rev: "&", branch_arrow: ">", bullet_point: "-", cycle_arrow: ">", @@ -204,6 +209,7 @@ impl Glyphs { commit_obsolete_head: "⦻", commit_omitted: "◌", commit_merge: "↓", + commit_merge_rev: "↑", commit_main: "◇", commit_main_head: "◆", commit_main_obsolete: "✕", @@ -223,6 +229,7 @@ impl Glyphs { pub fn reverse_order(mut self, reverse: bool) -> Self { if reverse { std::mem::swap(&mut self.split, &mut self.merge); + std::mem::swap(&mut self.commit_merge, &mut self.commit_merge_rev); } self }