Merge pull request #4840 from gitbutlerapp/rm-legacy-branch-applied-bool

removes the legacy bool indicatin a vbranch is applied
This commit is contained in:
Kiril Videlov 2024-09-06 15:55:42 +02:00 committed by GitHub
commit d4fd20bb57
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 8 additions and 66 deletions

View File

@ -248,7 +248,6 @@ pub(crate) fn set_base_branch(
order: 0,
selected_for_changes: None,
allow_rebasing: ctx.project().ok_with_force_push.into(),
applied: true,
in_workspace: true,
not_in_workspace_wip_change_id: None,
references: vec![],

View File

@ -110,7 +110,6 @@ impl BranchManager<'_> {
order,
selected_for_changes,
allow_rebasing: self.ctx.project().ok_with_force_push.into(),
applied: true,
in_workspace: true,
not_in_workspace_wip_change_id: None,
source_refname: None,
@ -237,7 +236,6 @@ impl BranchManager<'_> {
branch.order = order;
branch.selected_for_changes = selected_for_changes;
branch.allow_rebasing = self.ctx.project().ok_with_force_push.into();
branch.applied = true;
branch.in_workspace = true;
branch
@ -257,7 +255,6 @@ impl BranchManager<'_> {
order,
selected_for_changes,
allow_rebasing: self.ctx.project().ok_with_force_push.into(),
applied: true,
in_workspace: true,
not_in_workspace_wip_change_id: None,
references: vec![],

View File

@ -61,7 +61,6 @@ pub(crate) fn get_workspace_head(ctx: &CommandContext) -> Result<git2::Oid> {
} else {
// This branch should have already been unapplied during the "update" command but for some reason that failed
tracing::warn!("Merge conflict between base and {:?}", branch.name);
branch.applied = false;
branch.in_workspace = false;
vb_state.set_branch(branch.clone())?;
}

View File

@ -1,5 +1,4 @@
use crate::{
branch_manager::BranchManagerExt,
commit::{commit_to_vbranch_commit, VirtualBranchCommit},
conflicts::{self, RepoConflictsExt},
file::VirtualBranchFile,
@ -224,33 +223,6 @@ fn find_base_tree<'a>(
Ok(base_tree)
}
/// Resolves the "old_applied" state of branches
///
/// This should only ever be called by `list_virtual_branches
///
/// This checks for the case where !branch.old_applied && branch.in_workspace
/// If this is the case, we ought to unapply the branch as it has been carried
/// over from the old style of unapplying
fn fixup_old_applied_state(
ctx: &CommandContext,
vb_state: &VirtualBranchesHandle,
perm: &mut WorktreeWritePermission,
) -> Result<()> {
let branches = vb_state.list_all_branches()?;
let branch_manager = ctx.branch_manager();
for mut branch in branches {
if branch.is_old_unapplied() {
branch_manager.convert_to_real_branch(branch.id, perm)?;
} else if branch.applied != branch.in_workspace {
branch.applied = branch.in_workspace;
vb_state.set_branch(branch)?;
}
}
Ok(())
}
pub fn list_virtual_branches(
ctx: &CommandContext,
perm: &mut WorktreeWritePermission,
@ -275,8 +247,6 @@ pub fn list_virtual_branches_cached(
let vb_state = ctx.project().virtual_branches();
fixup_old_applied_state(ctx, &vb_state, perm)?;
let default_target = vb_state
.get_default_target()
.context("failed to get default target")?;

View File

@ -52,15 +52,6 @@ pub struct Branch {
pub selected_for_changes: Option<i64>,
#[serde(default = "default_true")]
pub allow_rebasing: bool,
/// This is the old metric for determining whether the branch is in the workspace
/// This is kept in sync with in_workspace
/// There should only be one condition where `applied` is false and `in_workspace`
/// true.
///
/// This is after updating, the `in_workspace` property will have defaulted to true
/// but the old `applied` property will have remained false.
#[serde(default = "default_true")]
pub applied: bool,
/// This is the new metric for determining whether the branch is in the workspace, which means it's applied
/// and its effects are available to the user.
#[serde(default = "default_true")]
@ -95,19 +86,6 @@ impl Branch {
pub fn refname(&self) -> anyhow::Result<VirtualRefname> {
self.try_into()
}
/// self.applied and self.in_workspace are kept in sync by the application
///
/// There is only once case where this might not be the case which is when
/// the user has upgraded to the new version for the fisrt time.
///
/// In this state, the `in_workspace` property will have defaulted to true
/// but the old `applied` property will have remained false.
///
/// This function indicates this state
pub fn is_old_unapplied(&self) -> bool {
!self.applied && self.in_workspace
}
}
impl TryFrom<&Branch> for VirtualRefname {

View File

@ -43,7 +43,7 @@ impl VirtualBranches {
self.list_all_branches().map(|branches| {
branches
.into_iter()
.filter(|branch| branch.in_workspace && !branch.is_old_unapplied())
.filter(|branch| branch.in_workspace)
.collect()
})
}
@ -110,7 +110,6 @@ impl VirtualBranchesHandle {
pub fn mark_as_not_in_workspace(&self, id: BranchId) -> Result<()> {
let mut branch = self.get_branch(id)?;
branch.in_workspace = false;
branch.applied = false;
self.set_branch(branch)?;
Ok(())
}
@ -152,9 +151,7 @@ impl VirtualBranchesHandle {
/// Gets the state of the given virtual branch returning `Some(branch)` or `None`
/// if that branch doesn't exist.
pub fn try_branch_in_workspace(&self, id: BranchId) -> Result<Option<Branch>> {
Ok(self
.try_branch(id)?
.filter(|branch| branch.in_workspace && !branch.is_old_unapplied()))
Ok(self.try_branch(id)?.filter(|branch| branch.in_workspace))
}
/// Gets the state of the given virtual branch returning `Some(branch)` or `None`
@ -180,7 +177,7 @@ impl VirtualBranchesHandle {
self.list_all_branches().map(|branches| {
branches
.into_iter()
.filter(|branch| branch.in_workspace && !branch.is_old_unapplied())
.filter(|branch| branch.in_workspace)
.collect()
})
}

View File

@ -35,7 +35,6 @@ fn reconcile_ownership_simple() {
order: usize::default(),
selected_for_changes: None,
allow_rebasing: true,
applied: true,
in_workspace: true,
not_in_workspace_wip_change_id: None,
source_refname: None,
@ -64,7 +63,6 @@ fn reconcile_ownership_simple() {
order: usize::default(),
selected_for_changes: None,
allow_rebasing: true,
applied: true,
in_workspace: true,
not_in_workspace_wip_change_id: None,
source_refname: None,

View File

@ -32,7 +32,11 @@ pub fn list(project: Project) -> Result<()> {
for vbranch in branches {
println!(
"{active} {id} {name} {upstream} {default}",
active = if vbranch.applied { "✔️" } else { "" },
active = if vbranch.in_workspace {
"✔️"
} else {
""
},
id = vbranch.id,
name = vbranch.name,
upstream = vbranch