Skip to content

Commit

Permalink
refactor(smartlog): Make [revset] an Option<Revset>
Browse files Browse the repository at this point in the history
This doesn't do much for us now, but will soon be used to help us determine
what type of smartlog we should be rendering.

Unfortunately, this prevents clap from rendering the default revset in
the help message, but I believe this is the only way (via the derive API)
to detect if the user has or has not not supplied an arg for a particular
value.

See clap-rs/clap#3846 fmi on getting the
value_source of an arg via the derive API.
  • Loading branch information
claytonrcarter committed Nov 7, 2022
1 parent 96396b4 commit ed260e9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
29 changes: 10 additions & 19 deletions git-branchless/src/commands/smartlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use lib::git::{GitRunInfo, Repo};
pub use graph::{make_smartlog_graph, SmartlogGraph};
pub use render::{render_graph, SmartlogOptions};

use crate::opts::Revset;
use crate::revset::resolve_commits;

mod graph {
Expand Down Expand Up @@ -500,7 +501,7 @@ mod render {
}

/// Options for rendering the smartlog.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct SmartlogOptions {
/// The point in time at which to show the smartlog. If not provided,
/// renders the smartlog as of the current time. If negative, is treated
Expand All @@ -509,20 +510,10 @@ mod render {

/// The commits to render. These commits and their ancestors up to the
/// main branch will be rendered.
pub revset: Revset,
pub revset: Option<Revset>,

pub resolve_revset_options: ResolveRevsetOptions,
}

impl Default for SmartlogOptions {
fn default() -> Self {
Self {
event_id: Default::default(),
revset: Revset("draft() | branches() | @".to_string()),
resolve_revset_options: Default::default(),
}
}
}
}

/// Display a nice graph of commits you've recently worked on.
Expand Down Expand Up @@ -566,13 +557,13 @@ pub fn smartlog(
&references_snapshot,
)?;

let commits = match resolve_commits(
effects,
&repo,
&mut dag,
&[revset.clone()],
resolve_revset_options,
) {
let revset = match revset {
Some(revset) => revset.clone(),
None => Revset("draft() | branches() | @".to_string()),
};

let commits = match resolve_commits(effects, &repo, &mut dag, &[revset], resolve_revset_options)
{
Ok(result) => match result.as_slice() {
[commit_set] => commit_set.clone(),
other => panic!(
Expand Down
4 changes: 2 additions & 2 deletions git-branchless/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ pub enum Command {

/// The commits to render. These commits and their ancestors up to the
/// main branch will be rendered.
#[clap(value_parser, default_value = "draft() | branches() | @")]
revset: Revset,
#[clap(value_parser)]
revset: Option<Revset>,

/// Options for resolving revset expressions.
#[clap(flatten)]
Expand Down
2 changes: 1 addition & 1 deletion git-branchless/tests/command/test_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ fn test_main_branch_not_found_error_message() -> eyre::Result<()> {
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
0: git_branchless::commands::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: Revset("draft() | branches() | @"), resolve_revset_options: ResolveRevsetOptions { show_hidden_commits: false } }
0: git_branchless::commands::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 } }
at some/file/path.rs:123
Suggestion:
Expand Down

0 comments on commit ed260e9

Please sign in to comment.