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: