Skip to content

Commit

Permalink
Restore --reverse flag with deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
e-q committed May 28, 2024
1 parent a565e2b commit d88f75d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
6 changes: 6 additions & 0 deletions git-branchless-opts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ pub struct SmartlogArgs {
#[clap(value_parser)]
pub revset: Option<Revset>,

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

Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -910,6 +929,7 @@ pub fn command_main(ctx: CommandContext, args: SmartlogArgs) -> EyreExitOr<()> {
event_id,
revset,
resolve_revset_options,
reverse,
exact,
} = args;

Expand All @@ -920,6 +940,7 @@ 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 }, 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 }, reverse: 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, 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, reverse: false, exact: false, resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false } }
at some/file/path.rs:123
Suggestion:
Expand Down

0 comments on commit d88f75d

Please sign in to comment.