Skip to content

Commit 3cac073

Browse files
1 parent a3a4964 commit 3cac073

File tree

3 files changed

+24
-61
lines changed

3 files changed

+24
-61
lines changed

git-branchless-lib/src/core/dag.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -296,28 +296,6 @@ impl Dag {
296296
Ok(dag)
297297
}
298298

299-
/// Get one of the merge-base OIDs for the given pair of OIDs. If there are
300-
/// multiple possible merge-bases, one is arbitrarily returned.
301-
#[instrument]
302-
pub fn get_one_merge_base_oid(
303-
&self,
304-
effects: &Effects,
305-
repo: &Repo,
306-
lhs_oid: NonZeroOid,
307-
rhs_oid: NonZeroOid,
308-
) -> eyre::Result<Option<NonZeroOid>> {
309-
let set = vec![CommitVertex::from(lhs_oid), CommitVertex::from(rhs_oid)];
310-
let set = self
311-
.inner
312-
.sort(&CommitSet::from_static_names(set))
313-
.wrap_err("Sorting DAG vertex set")?;
314-
let vertex = self.inner.gca_one(set).wrap_err("Computing merge-base")?;
315-
match vertex {
316-
None => Ok(None),
317-
Some(vertex) => Ok(Some(vertex.to_hex().parse()?)),
318-
}
319-
}
320-
321299
/// Get the parent OID for the given OID. Returns an error if the given OID
322300
/// does not have exactly 1 parent.
323301
#[instrument]
@@ -429,32 +407,6 @@ impl Dag {
429407
})
430408
}
431409

432-
/// Find a path from the provided head to its merge-base with the main
433-
/// branch.
434-
#[instrument]
435-
pub fn find_path_to_main_branch(
436-
&self,
437-
effects: &Effects,
438-
head: CommitSet,
439-
) -> eyre::Result<Option<CommitSet>> {
440-
// FIXME: this assumes that there is only one merge-base with the main branch.
441-
let merge_base = {
442-
let (_effects, _progress) = effects.start_operation(OperationType::GetMergeBase);
443-
self.query().gca_one(self.main_branch_commit.union(&head))?
444-
};
445-
let merge_base = match merge_base {
446-
Some(merge_base) => merge_base,
447-
None => return Ok(None),
448-
};
449-
450-
// FIXME: this assumes that there is only one path to the merge-base.
451-
let path = {
452-
let (_effects, _progress) = effects.start_operation(OperationType::FindPathToMergeBase);
453-
self.query().range(CommitSet::from(merge_base), head)?
454-
};
455-
Ok(Some(path))
456-
}
457-
458410
/// Given a CommitSet, return a list of CommitSets, each representing a
459411
/// connected component of the set.
460412
///

git-branchless/src/commands/move.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::convert::TryFrom;
88
use std::fmt::Write;
99
use std::time::SystemTime;
1010

11-
use eden_dag::DagAlgorithm;
11+
use eden_dag::{DagAlgorithm, VertexName};
1212
use lib::core::repo_ext::RepoExt;
1313
use lib::util::ExitCode;
1414
use rayon::ThreadPoolBuilder;
@@ -32,7 +32,7 @@ use lib::git::{GitRunInfo, NonZeroOid, Repo};
3232
#[instrument]
3333
fn resolve_base_commit(
3434
dag: &Dag,
35-
merge_base_oid: Option<NonZeroOid>,
35+
merge_base_oid: Option<VertexName>,
3636
oid: NonZeroOid,
3737
) -> eyre::Result<NonZeroOid> {
3838
let bases = match merge_base_oid {
@@ -207,7 +207,9 @@ pub fn r#move(
207207
let base_oids = {
208208
let mut result = Vec::new();
209209
for base_oid in commit_set_to_vec(&base_oids)? {
210-
let merge_base_oid = dag.get_one_merge_base_oid(effects, &repo, base_oid, dest_oid)?;
210+
let merge_base_oid = dag
211+
.query()
212+
.gca_one(vec![base_oid, dest_oid].into_iter().collect::<CommitSet>())?;
211213
let base_commit_oid = resolve_base_commit(&dag, merge_base_oid, base_oid)?;
212214
result.push(CommitSet::from(base_commit_oid))
213215
}

git-branchless/src/commands/smartlog.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,20 @@ mod graph {
231231
// Find the nearest ancestor that is included in the graph and
232232
// also on the same branch.
233233

234-
let nearest_branch_ancestor = match dag
235-
.find_path_to_main_branch(effects, CommitSet::from(parent_oid))?
236-
{
237-
Some(path_to_main_branch) => dag.query().heads_ancestors(
238-
path_to_main_branch.intersection(&graph_vertices),
239-
)?,
234+
let parent_set = CommitSet::from(parent_oid);
235+
let merge_base = dag
236+
.query()
237+
.gca_one(dag.main_branch_commit.union(&parent_set))?;
238+
239+
let path_to_main_branch = match merge_base {
240+
Some(merge_base) => {
241+
dag.query().range(CommitSet::from(merge_base), parent_set)?
242+
}
240243
None => CommitSet::empty(),
241244
};
245+
let nearest_branch_ancestor = dag
246+
.query()
247+
.heads_ancestors(path_to_main_branch.intersection(&graph_vertices))?;
242248

243249
let ancestor_oids = commit_set_to_vec(&nearest_branch_ancestor)?;
244250
for ancestor_oid in ancestor_oids.iter() {
@@ -414,6 +420,7 @@ mod graph {
414420
mod render {
415421
use std::cmp::Ordering;
416422
use std::collections::HashSet;
423+
use std::convert::TryFrom;
417424

418425
use cursive::theme::Effect;
419426
use cursive::utils::markup::StyledString;
@@ -440,7 +447,6 @@ mod render {
440447
/// Returns the list such that the topologically-earlier subgraphs are first in
441448
/// the list (i.e. those that would be rendered at the bottom of the smartlog).
442449
fn split_commit_graph_by_roots(
443-
effects: &Effects,
444450
repo: &Repo,
445451
dag: &Dag,
446452
graph: &SmartlogGraph,
@@ -465,10 +471,13 @@ mod render {
465471
_ => return lhs_oid.cmp(rhs_oid),
466472
};
467473

468-
let merge_base_oid = dag.get_one_merge_base_oid(effects, repo, *lhs_oid, *rhs_oid);
474+
let merge_base_oid = dag
475+
.query()
476+
.gca_one(vec![*lhs_oid, *rhs_oid].into_iter().collect::<CommitSet>());
469477
let merge_base_oid = match merge_base_oid {
470478
Err(_) => return lhs_oid.cmp(rhs_oid),
471-
Ok(merge_base_oid) => merge_base_oid,
479+
Ok(None) => None,
480+
Ok(Some(merge_base_oid)) => NonZeroOid::try_from(merge_base_oid).ok(),
472481
};
473482

474483
match merge_base_oid {
@@ -698,7 +707,7 @@ mod render {
698707
head_oid: Option<NonZeroOid>,
699708
commit_descriptors: &mut [&mut dyn NodeDescriptor],
700709
) -> eyre::Result<Vec<StyledString>> {
701-
let root_oids = split_commit_graph_by_roots(effects, repo, dag, graph);
710+
let root_oids = split_commit_graph_by_roots(repo, dag, graph);
702711
let lines = get_output(
703712
effects.get_glyphs(),
704713
dag,

0 commit comments

Comments
 (0)