Skip to content

Commit

Permalink
refactor(dag): Remove legacy functions
Browse files Browse the repository at this point in the history
  • Loading branch information
claytonrcarter committed Nov 9, 2022
1 parent ae3b28a commit f53e1f9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 55 deletions.
48 changes: 0 additions & 48 deletions git-branchless-lib/src/core/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,28 +298,6 @@ impl Dag {
Ok(dag)
}

/// Get one of the merge-base OIDs for the given pair of OIDs. If there are
/// multiple possible merge-bases, one is arbitrarily returned.
#[instrument]
pub fn get_one_merge_base_oid(
&self,
effects: &Effects,
repo: &Repo,
lhs_oid: NonZeroOid,
rhs_oid: NonZeroOid,
) -> eyre::Result<Option<NonZeroOid>> {
let set = vec![CommitVertex::from(lhs_oid), CommitVertex::from(rhs_oid)];
let set = self
.inner
.sort(&CommitSet::from_static_names(set))
.wrap_err("Sorting DAG vertex set")?;
let vertex = self.inner.gca_one(set).wrap_err("Computing merge-base")?;
match vertex {
None => Ok(None),
Some(vertex) => Ok(Some(vertex.to_hex().parse()?)),
}
}

/// Get the parent OID for the given OID. Returns an error if the given OID
/// does not have exactly 1 parent.
#[instrument]
Expand Down Expand Up @@ -474,32 +452,6 @@ impl Dag {
})
}

/// Find a path from the provided head to its merge-base with the main
/// branch.
#[instrument]
pub fn find_path_to_main_branch(
&self,
effects: &Effects,
head: CommitSet,
) -> eyre::Result<Option<CommitSet>> {
// FIXME: this assumes that there is only one merge-base with the main branch.
let merge_base = {
let (_effects, _progress) = effects.start_operation(OperationType::GetMergeBase);
self.query().gca_one(self.main_branch_commit.union(&head))?
};
let merge_base = match merge_base {
Some(merge_base) => merge_base,
None => return Ok(None),
};

// FIXME: this assumes that there is only one path to the merge-base.
let path = {
let (_effects, _progress) = effects.start_operation(OperationType::FindPathToMergeBase);
self.query().range(CommitSet::from(merge_base), head)?
};
Ok(Some(path))
}

/// Given a CommitSet, return a list of CommitSets, each representing a
/// connected component of the set.
///
Expand Down
8 changes: 5 additions & 3 deletions git-branchless/src/commands/move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::convert::TryFrom;
use std::fmt::Write;
use std::time::SystemTime;

use eden_dag::DagAlgorithm;
use eden_dag::{DagAlgorithm, VertexName};
use lib::core::repo_ext::RepoExt;
use lib::util::ExitCode;
use rayon::ThreadPoolBuilder;
Expand All @@ -32,7 +32,7 @@ use lib::git::{GitRunInfo, NonZeroOid, Repo};
#[instrument]
fn resolve_base_commit(
dag: &Dag,
merge_base_oid: Option<NonZeroOid>,
merge_base_oid: Option<VertexName>,
oid: NonZeroOid,
) -> eyre::Result<NonZeroOid> {
let bases = match merge_base_oid {
Expand Down Expand Up @@ -207,7 +207,9 @@ pub fn r#move(
let base_oids = {
let mut result = Vec::new();
for base_oid in commit_set_to_vec(&base_oids)? {
let merge_base_oid = dag.get_one_merge_base_oid(effects, &repo, base_oid, dest_oid)?;
let merge_base_oid = dag
.query()
.gca_one(vec![base_oid, dest_oid].into_iter().collect::<CommitSet>())?;
let base_commit_oid = resolve_base_commit(&dag, merge_base_oid, base_oid)?;
result.push(CommitSet::from(base_commit_oid))
}
Expand Down
11 changes: 7 additions & 4 deletions git-branchless/src/commands/smartlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ mod graph {

mod render {
use std::cmp::Ordering;
use std::convert::TryFrom;

use cursive::theme::Effect;
use cursive::utils::markup::StyledString;
Expand All @@ -262,7 +263,6 @@ mod render {
/// Returns the list such that the topologically-earlier subgraphs are first in
/// the list (i.e. those that would be rendered at the bottom of the smartlog).
fn split_commit_graph_by_roots(
effects: &Effects,
repo: &Repo,
dag: &Dag,
graph: &SmartlogGraph,
Expand All @@ -284,10 +284,13 @@ mod render {
_ => return lhs_oid.cmp(rhs_oid),
};

let merge_base_oid = dag.get_one_merge_base_oid(effects, repo, *lhs_oid, *rhs_oid);
let merge_base_oid = dag
.query()
.gca_one(vec![*lhs_oid, *rhs_oid].into_iter().collect::<CommitSet>());
let merge_base_oid = match merge_base_oid {
Err(_) => return lhs_oid.cmp(rhs_oid),
Ok(merge_base_oid) => merge_base_oid,
Ok(None) => None,
Ok(Some(merge_base_oid)) => NonZeroOid::try_from(merge_base_oid).ok(),
};

match merge_base_oid {
Expand Down Expand Up @@ -485,7 +488,7 @@ mod render {
head_oid: Option<NonZeroOid>,
commit_descriptors: &mut [&mut dyn NodeDescriptor],
) -> eyre::Result<Vec<StyledString>> {
let root_oids = split_commit_graph_by_roots(effects, repo, dag, graph);
let root_oids = split_commit_graph_by_roots(repo, dag, graph);
let lines = get_output(
effects.get_glyphs(),
dag,
Expand Down

0 comments on commit f53e1f9

Please sign in to comment.