mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-19 23:52:05 +03:00
Base branch: Use graph ahead behind
This commit is contained in:
parent
d8b2bee18c
commit
265d957fb3
@ -564,33 +564,25 @@ pub(crate) fn target_to_base_branch(ctx: &CommandContext, target: &Target) -> Re
|
|||||||
let commit = branch.get().peel_to_commit()?;
|
let commit = branch.get().peel_to_commit()?;
|
||||||
let oid = commit.id();
|
let oid = commit.id();
|
||||||
|
|
||||||
// determined if the base branch is behind it's upstream
|
// determine if the base branch is behind it's upstream
|
||||||
let fork_point = repo.merge_base(target.sha, oid).context(format!(
|
let (number_commits_ahead, number_commits_behind) = repo.graph_ahead_behind(target.sha, oid)?;
|
||||||
"failed to find merge base between {} and {}",
|
|
||||||
target.sha, oid
|
|
||||||
))?;
|
|
||||||
|
|
||||||
let diverged = fork_point != target.sha;
|
let diverged_ahead = repo
|
||||||
|
.log(target.sha, LogUntil::Take(number_commits_ahead))
|
||||||
|
.context("failed to get fork point")?
|
||||||
|
.iter()
|
||||||
|
.map(|commit| commit.id())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let diverged_ahead = if diverged {
|
let diverged_behind = repo
|
||||||
repo.log(target.sha, LogUntil::Commit(fork_point))
|
.log(oid, LogUntil::Take(number_commits_behind))
|
||||||
.context("failed to get diverged ahead commits")?
|
.context("failed to get fork point")?
|
||||||
.iter()
|
.iter()
|
||||||
.map(|commit| commit.id())
|
.map(|commit| commit.id())
|
||||||
.collect::<Vec<git2::Oid>>()
|
.collect::<Vec<_>>();
|
||||||
} else {
|
|
||||||
Vec::new()
|
|
||||||
};
|
|
||||||
|
|
||||||
let diverged_behind = if diverged {
|
// if there are commits ahead of the base branch consider it diverged
|
||||||
repo.log(oid, LogUntil::Commit(fork_point))
|
let diverged = !diverged_ahead.is_empty();
|
||||||
.context("failed to get diverged behind commits")?
|
|
||||||
.iter()
|
|
||||||
.map(|commit| commit.id())
|
|
||||||
.collect::<Vec<git2::Oid>>()
|
|
||||||
} else {
|
|
||||||
Vec::new()
|
|
||||||
};
|
|
||||||
|
|
||||||
// gather a list of commits between oid and target.sha
|
// gather a list of commits between oid and target.sha
|
||||||
let upstream_commits = repo
|
let upstream_commits = repo
|
||||||
|
Loading…
Reference in New Issue
Block a user