Skip to content

Commit 804ed86

Browse files
feat(smartlog): Introduce SmartlogVariant
As implemented, these variants don't actually do anything. That will change with the next commit, as we use the variants to decide what commits to render and how to render them.
1 parent 6e64194 commit 804ed86

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

git-branchless/src/commands/smartlog.rs

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use lib::core::node_descriptors::{
2525
};
2626
use lib::git::{GitRunInfo, Repo};
2727

28-
pub use graph::{make_smartlog_graph, SmartlogGraph};
28+
pub use graph::{make_custom_smartlog_graph, make_smartlog_graph, SmartlogGraph, SmartlogVariant};
2929
pub use render::{render_graph, SmartlogOptions};
3030

3131
use crate::opts::Revset;
@@ -211,7 +211,23 @@ mod graph {
211211
}
212212
}
213213

214-
/// Construct the smartlog graph for the repo.
214+
/// What kind of smartlog is desired?
215+
#[derive(Debug)]
216+
pub enum SmartlogVariant {
217+
/// A smartlog with all commits connected back to the main branch.
218+
Connected,
219+
220+
/// A smartlog with only the specified set of a commits.
221+
Sparse,
222+
}
223+
224+
impl Default for SmartlogVariant {
225+
fn default() -> Self {
226+
SmartlogVariant::Connected
227+
}
228+
}
229+
230+
/// Construct the default smartlog graph for the repo.
215231
#[instrument]
216232
pub fn make_smartlog_graph<'repo>(
217233
effects: &Effects,
@@ -220,13 +236,41 @@ mod graph {
220236
event_replayer: &EventReplayer,
221237
event_cursor: EventCursor,
222238
commits: &CommitSet,
239+
) -> eyre::Result<SmartlogGraph<'repo>> {
240+
make_custom_smartlog_graph(
241+
effects,
242+
repo,
243+
dag,
244+
event_replayer,
245+
event_cursor,
246+
commits,
247+
SmartlogVariant::default(),
248+
)
249+
}
250+
251+
/// Construct a specific kind of smartlog graph for the repo.
252+
#[instrument]
253+
pub fn make_custom_smartlog_graph<'repo>(
254+
effects: &Effects,
255+
repo: &'repo Repo,
256+
dag: &Dag,
257+
event_replayer: &EventReplayer,
258+
event_cursor: EventCursor,
259+
commits: &CommitSet,
260+
smartlog_variant: SmartlogVariant,
223261
) -> eyre::Result<SmartlogGraph<'repo>> {
224262
let (effects, _progress) = effects.start_operation(OperationType::MakeGraph);
225263

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

229267
let public_commits = dag.query_public_commits()?;
268+
269+
let commits = match smartlog_variant {
270+
SmartlogVariant::Connected => commits,
271+
SmartlogVariant::Sparse => commits,
272+
};
273+
230274
for oid in commit_set_to_vec(commits)? {
231275
mark_commit_reachable(repo, oid)?;
232276
}
@@ -557,9 +601,9 @@ pub fn smartlog(
557601
&references_snapshot,
558602
)?;
559603

560-
let revset = match revset {
561-
Some(revset) => revset.clone(),
562-
None => Revset::default(),
604+
let (revset, smartlog_variant) = match revset {
605+
Some(revset) => (revset.clone(), SmartlogVariant::Sparse),
606+
None => (Revset::default(), SmartlogVariant::Connected),
563607
};
564608

565609
let commits = match resolve_commits(effects, &repo, &mut dag, &[revset], resolve_revset_options)
@@ -577,13 +621,14 @@ pub fn smartlog(
577621
}
578622
};
579623

580-
let graph = make_smartlog_graph(
624+
let graph = make_custom_smartlog_graph(
581625
effects,
582626
&repo,
583627
&dag,
584628
&event_replayer,
585629
event_cursor,
586630
&commits,
631+
smartlog_variant,
587632
)?;
588633

589634
let lines = render_graph(

git-branchless/src/opts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::str::FromStr;
88

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

1414
impl FromStr for Revset {

0 commit comments

Comments
 (0)