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-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 } diff --git a/git-branchless-opts/src/lib.rs b/git-branchless-opts/src/lib.rs index 131eea0e1..1ed27995e 100644 --- a/git-branchless-opts/src/lib.rs +++ b/git-branchless-opts/src/lib.rs @@ -340,8 +340,9 @@ 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. + /// commits first. Can be configured via `branchless.smartlog.reverse`. #[clap(long)] pub reverse: bool, diff --git a/git-branchless-smartlog/src/lib.rs b/git-branchless-smartlog/src/lib.rs index e3b3bdc3f..0677ac5e6 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,6 +747,7 @@ 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, @@ -825,8 +826,22 @@ pub fn smartlog( exact, )?; + 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, @@ -849,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() 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 |