Skip to content

Commit 1db35ff

Browse files
committed
smartlog: replace --reverse flag with config opt
1 parent ce1aa49 commit 1db35ff

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

git-branchless-lib/src/core/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ pub fn get_smartlog_default_revset(repo: &Repo) -> eyre::Result<String> {
108108
})
109109
}
110110

111+
/// Whether to reverse the smartlog direction by default
112+
#[instrument]
113+
pub fn get_smartlog_reverse(repo: &Repo) -> eyre::Result<bool> {
114+
repo.get_readonly_config()?
115+
.get_or("branchless.smartlog.reverse", false)
116+
}
117+
111118
/// Get the default comment character.
112119
#[instrument]
113120
pub fn get_comment_char(repo: &Repo) -> eyre::Result<char> {

git-branchless-opts/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,6 @@ pub struct SmartlogArgs {
340340
#[clap(value_parser)]
341341
pub revset: Option<Revset>,
342342

343-
/// Print the smartlog in the opposite of the usual order, with the latest
344-
/// commits first.
345-
#[clap(long)]
346-
pub reverse: bool,
347-
348343
/// Don't automatically add HEAD and the main branch to the list of commits
349344
/// to present. They will still be added if included in the revset.
350345
#[clap(long)]

git-branchless-smartlog/src/lib.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use std::time::SystemTime;
1919
use git_branchless_invoke::CommandContext;
2020
use git_branchless_opts::{Revset, SmartlogArgs};
2121
use lib::core::config::{
22-
get_hint_enabled, get_hint_string, get_smartlog_default_revset, print_hint_suppression_notice,
23-
Hint,
22+
get_hint_enabled, get_hint_string, get_smartlog_default_revset, get_smartlog_reverse,
23+
print_hint_suppression_notice, Hint,
2424
};
2525
use lib::core::repo_ext::RepoExt;
2626
use lib::core::rewrite::find_rewrite_target;
@@ -747,10 +747,6 @@ mod render {
747747
/// The options to use when resolving the revset.
748748
pub resolve_revset_options: ResolveRevsetOptions,
749749

750-
/// Reverse the ordering of items in the smartlog output, list the most
751-
/// recent commits first.
752-
pub reverse: bool,
753-
754750
/// Normally HEAD and the main branch are included. Set this to exclude them.
755751
pub exact: bool,
756752
}
@@ -767,7 +763,6 @@ pub fn smartlog(
767763
event_id,
768764
revset,
769765
resolve_revset_options,
770-
reverse,
771766
exact,
772767
} = options;
773768

@@ -825,6 +820,7 @@ pub fn smartlog(
825820
exact,
826821
)?;
827822

823+
let reverse = get_smartlog_reverse(&repo)?;
828824
let mut lines = render_graph(
829825
&effects.reverse_order(reverse),
830826
&repo,
@@ -914,7 +910,6 @@ pub fn command_main(ctx: CommandContext, args: SmartlogArgs) -> EyreExitOr<()> {
914910
event_id,
915911
revset,
916912
resolve_revset_options,
917-
reverse,
918913
exact,
919914
} = args;
920915

@@ -925,7 +920,6 @@ pub fn command_main(ctx: CommandContext, args: SmartlogArgs) -> EyreExitOr<()> {
925920
event_id,
926921
revset,
927922
resolve_revset_options,
928-
reverse,
929923
exact,
930924
},
931925
)

git-branchless-smartlog/tests/test_smartlog.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ fn test_merge_commit_reverse_order() -> eyre::Result<()> {
183183
let git = make_git()?;
184184

185185
git.init_repo()?;
186+
git.run(&["config", "branchless.smartlog.reverse", "true"])?;
186187
git.run(&["checkout", "-b", "test1", "master"])?;
187188
git.commit_file("test1", 1)?;
188189
git.run(&["checkout", "-b", "test2and3", "master"])?;
@@ -196,7 +197,7 @@ fn test_merge_commit_reverse_order() -> eyre::Result<()> {
196197
},
197198
)?;
198199

199-
let (stdout, _) = git.branchless("smartlog", &["--reverse"])?;
200+
let (stdout, _) = git.branchless("smartlog", &[])?;
200201
insta::assert_snapshot!(stdout, @r###"
201202
@ fa4e4e1 (> test2and3) Merge branch 'test1' into test2and3
202203
|\
@@ -499,7 +500,7 @@ fn test_smartlog_hint_abandoned_except_current_commit() -> eyre::Result<()> {
499500
Ok(())
500501
}
501502

502-
/// When --reverse is specified hints still appear at the end of output
503+
/// When branchless.smartlog.reverse is `true`, hints still appear at the end of output
503504
#[test]
504505
fn test_smartlog_hint_abandoned_reverse_order() -> eyre::Result<()> {
505506
let git = make_git()?;
@@ -508,14 +509,15 @@ fn test_smartlog_hint_abandoned_reverse_order() -> eyre::Result<()> {
508509
return Ok(());
509510
}
510511
git.init_repo()?;
512+
git.run(&["config", "branchless.smartlog.reverse", "true"])?;
511513

512514
git.detach_head()?;
513515
git.commit_file("test1", 1)?;
514516
git.commit_file("test2", 2)?;
515517
git.run(&["checkout", "HEAD^"])?;
516518
git.run(&["commit", "--amend", "-m", "amended test1"])?;
517519

518-
let (stdout, _) = git.branchless("smartlog", &["--reverse"])?;
520+
let (stdout, _) = git.branchless("smartlog", &[])?;
519521
insta::assert_snapshot!(stdout, @r###"
520522
o 96d1c37 create test2.txt
521523
|

git-branchless/tests/test_init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ fn test_main_branch_not_found_error_message() -> eyre::Result<()> {
316316
317317
0: branchless::core::eventlog::from_event_log_db with effects=<Output fancy=false> repo=<Git repository at: "<repo-path>/.git/"> event_log_db=<EventLogDb path=Some("<repo-path>/.git/branchless/db.sqlite3")>
318318
at some/file/path.rs:123
319-
1: git_branchless_smartlog::smartlog with effects=<Output fancy=false> git_run_info=<GitRunInfo path_to_git="<git-executable>" working_directory="<repo-path>" env=not shown> options=SmartlogOptions { event_id: None, revset: None, resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false }, reverse: false, exact: false }
319+
1: git_branchless_smartlog::smartlog with effects=<Output fancy=false> git_run_info=<GitRunInfo path_to_git="<git-executable>" working_directory="<repo-path>" env=not shown> options=SmartlogOptions { event_id: None, revset: None, resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false }, exact: false }
320320
at some/file/path.rs:123
321-
2: git_branchless_smartlog::command_main with ctx=CommandContext { effects: <Output fancy=false>, git_run_info: <GitRunInfo path_to_git="<git-executable>" working_directory="<repo-path>" env=not shown> } args=SmartlogArgs { event_id: None, revset: None, reverse: false, exact: false, resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false } }
321+
2: git_branchless_smartlog::command_main with ctx=CommandContext { effects: <Output fancy=false>, git_run_info: <GitRunInfo path_to_git="<git-executable>" working_directory="<repo-path>" env=not shown> } args=SmartlogArgs { event_id: None, revset: None, exact: false, resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false } }
322322
at some/file/path.rs:123
323323
324324
Suggestion:

0 commit comments

Comments
 (0)