Skip to content

Commit

Permalink
smartlog: replace --reverse flag with config opt
Browse files Browse the repository at this point in the history
  • Loading branch information
e-q committed May 20, 2024
1 parent ce1aa49 commit 9ba6da9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
7 changes: 7 additions & 0 deletions git-branchless-lib/src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ pub fn get_smartlog_default_revset(repo: &Repo) -> eyre::Result<String> {
})
}

/// Whether to reverse the smartlog direction by default
#[instrument]
pub fn get_smartlog_reverse(repo: &Repo) -> eyre::Result<bool> {
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<char> {
Expand Down
5 changes: 0 additions & 5 deletions git-branchless-opts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,6 @@ pub struct SmartlogArgs {
#[clap(value_parser)]
pub revset: Option<Revset>,

/// 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)]
Expand Down
12 changes: 3 additions & 9 deletions git-branchless-smartlog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
}
Expand All @@ -767,7 +763,6 @@ pub fn smartlog(
event_id,
revset,
resolve_revset_options,
reverse,
exact,
} = options;

Expand Down Expand Up @@ -825,6 +820,7 @@ pub fn smartlog(
exact,
)?;

let reverse = get_smartlog_reverse(&repo)?;
let mut lines = render_graph(
&effects.reverse_order(reverse),
&repo,
Expand Down Expand Up @@ -914,7 +910,6 @@ pub fn command_main(ctx: CommandContext, args: SmartlogArgs) -> EyreExitOr<()> {
event_id,
revset,
resolve_revset_options,
reverse,
exact,
} = args;

Expand All @@ -925,7 +920,6 @@ pub fn command_main(ctx: CommandContext, args: SmartlogArgs) -> EyreExitOr<()> {
event_id,
revset,
resolve_revset_options,
reverse,
exact,
},
)
Expand Down
4 changes: 2 additions & 2 deletions git-branchless/tests/test_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ fn test_main_branch_not_found_error_message() -> eyre::Result<()> {
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")>
at some/file/path.rs:123
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 }
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 }
at some/file/path.rs:123
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 } }
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 } }
at some/file/path.rs:123
Suggestion:
Expand Down

0 comments on commit 9ba6da9

Please sign in to comment.