Skip to content

Commit

Permalink
temp: feat(smartlog): Only HEAD and main should be mandatory in the s…
Browse files Browse the repository at this point in the history
…martlog

Interactive undo needs to display a lot more context, so its behavior is
preserved.
  • Loading branch information
claytonrcarter committed Nov 5, 2022
1 parent e1bcc27 commit 083114a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 12 deletions.
70 changes: 59 additions & 11 deletions git-branchless/src/commands/smartlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use lib::core::node_descriptors::{
};
use lib::git::{ConfigRead, GitRunInfo, Repo};

pub use graph::{make_smartlog_graph, SmartlogGraph};
pub use graph::{make_custom_smartlog_graph, make_smartlog_graph, SmartLogKind, SmartlogGraph};
pub use render::{render_graph, SmartlogOptions};

use crate::opts::Revset;
Expand Down Expand Up @@ -211,7 +211,18 @@ mod graph {
}
}

/// Construct the smartlog graph for the repo.
/// What kind of smartlog is desired?
#[derive(Debug)]
pub enum SmartLogKind {
/// The default smartlog, with all draft commits visible.
Default,

/// A smartlog representing only a specific set of a commits, such when
/// a user calls `smartlog` and specifies a revset .
Specific,
}

/// Construct the default smartlog graph for the repo.
#[instrument]
pub fn make_smartlog_graph<'repo>(
effects: &Effects,
Expand All @@ -220,18 +231,52 @@ mod graph {
event_replayer: &EventReplayer,
event_cursor: EventCursor,
commits: &CommitSet,
) -> eyre::Result<SmartlogGraph<'repo>> {
make_custom_smartlog_graph(
effects,
repo,
dag,
event_replayer,
event_cursor,
commits,
SmartLogKind::Default,
)
}

/// Construct a specific kind of smartlog graph for the repo.
#[instrument]
pub fn make_custom_smartlog_graph<'repo>(
effects: &Effects,
repo: &'repo Repo,
dag: &Dag,
event_replayer: &EventReplayer,
event_cursor: EventCursor,
commits: &CommitSet,
smartlog_kind: SmartLogKind,
) -> eyre::Result<SmartlogGraph<'repo>> {
let (effects, _progress) = effects.start_operation(OperationType::MakeGraph);

let mut graph = {
let (effects, _progress) = effects.start_operation(OperationType::WalkCommits);

let public_commits = dag.query_public_commits()?;
for oid in commit_set_to_vec(commits)? {

let commits = match smartlog_kind {
SmartLogKind::Default => commits.clone(),
SmartLogKind::Specific => {
// The only 2 commits that *must* be displayed are HEAD and
// main/master head.
commits
.union(&dag.head_commit)
.union(&dag.main_branch_commit)
}
};

for oid in commit_set_to_vec(&commits)? {
mark_commit_reachable(repo, oid)?;
}

walk_from_commits(&effects, repo, dag, public_commits, commits)?
walk_from_commits(&effects, repo, dag, public_commits, &commits)?
};
sort_children(&mut graph);
Ok(graph)
Expand Down Expand Up @@ -557,16 +602,18 @@ pub fn smartlog(
&references_snapshot,
)?;

let revset = match revset {
Some(revset) => revset.clone(),
let default_revset = Revset("draft()".to_string());
let (revset, smartlog_kind) = match revset {
Some(revset) if revset == &default_revset => (revset.clone(), SmartLogKind::Default),
Some(revset) => (revset.clone(), SmartLogKind::Specific),
None => {
// TODO add test for custom default revset
let custom_default: Option<String> = repo
let user_default: Option<String> = repo
.get_readonly_config()?
.get("branchless.revsets.default")?;
match custom_default {
Some(custom_default) => Revset(custom_default),
None => Revset::default(),
match user_default {
Some(user_default) => (Revset(user_default), SmartLogKind::Specific),
None => (Revset::default(), SmartLogKind::Default),
}
}
};
Expand All @@ -586,13 +633,14 @@ pub fn smartlog(
}
};

let graph = make_smartlog_graph(
let graph = make_custom_smartlog_graph(
effects,
&repo,
&dag,
&event_replayer,
event_cursor,
&commits,
smartlog_kind,
)?;

let lines = render_graph(
Expand Down
2 changes: 1 addition & 1 deletion git-branchless/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::str::FromStr;

/// A revset expression. Can be a commit hash, branch name, or one of the
/// various revset functions.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Revset(pub String);

impl FromStr for Revset {
Expand Down

0 comments on commit 083114a

Please sign in to comment.