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 6135b32
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 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

0 comments on commit 6135b32

Please sign in to comment.