From 9ba6da961b0e581aa2f280654f218ef2166756df Mon Sep 17 00:00:00 2001 From: e-q Date: Mon, 20 May 2024 11:35:48 -0400 Subject: [PATCH] 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/tests/test_init.rs | 4 ++-- 4 files changed, 12 insertions(+), 16 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/tests/test_init.rs b/git-branchless/tests/test_init.rs index d0d8d8b14..f89680114 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: