Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smartlog: replace --reverse flag with config opt #1315

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 7 additions & 0 deletions git-branchless-lib/src/core/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -179,6 +183,7 @@ impl Glyphs {
commit_main_obsolete_head: "%",
commit_omitted: "#",
commit_merge: "&",
commit_merge_rev: "&",
branch_arrow: ">",
bullet_point: "-",
cycle_arrow: ">",
Expand All @@ -204,6 +209,7 @@ impl Glyphs {
commit_obsolete_head: "⦻",
commit_omitted: "◌",
commit_merge: "↓",
commit_merge_rev: "↑",
commit_main: "◇",
commit_main_head: "◆",
commit_main_obsolete: "✕",
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion git-branchless-opts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@ 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.
/// commits first. Can be configured via `branchless.smartlog.reverse`.
#[clap(long)]
pub reverse: bool,

Expand Down
23 changes: 19 additions & 4 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,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,
Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand Down
8 changes: 5 additions & 3 deletions git-branchless-smartlog/tests/test_smartlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"])?;
Expand All @@ -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
|\
Expand Down Expand Up @@ -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()?;
Expand All @@ -508,14 +509,15 @@ 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)?;
git.commit_file("test2", 2)?;
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
|
Expand Down
Loading