Fix migration code

This commit is contained in:
Caleb Owens 2024-07-09 22:21:05 +02:00
parent ddc9b33f77
commit 9f13291edb
No known key found for this signature in database
6 changed files with 36 additions and 12 deletions

View File

@ -46,8 +46,16 @@ pub struct Branch {
pub selected_for_changes: Option<i64>,
#[serde(default = "default_true")]
pub allow_rebasing: bool,
#[serde(default = "default_true", rename = "applied")]
pub old_applied: 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
#[serde(default = "default_true")]
pub in_workspace: bool,
#[serde(default)]
@ -78,6 +86,19 @@ impl Branch {
pub fn refname(&self) -> VirtualRefname {
self.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 From<&Branch> for VirtualRefname {

View File

@ -41,7 +41,7 @@ fn reconcile_ownership_simple() {
order: usize::default(),
selected_for_changes: None,
allow_rebasing: true,
old_applied: true,
applied: true,
in_workspace: true,
not_in_workspace_wip_change_id: None,
source_refname: None,
@ -70,7 +70,7 @@ fn reconcile_ownership_simple() {
order: usize::default(),
selected_for_changes: None,
allow_rebasing: true,
old_applied: true,
applied: true,
in_workspace: true,
not_in_workspace_wip_change_id: None,
source_refname: None,

View File

@ -120,7 +120,7 @@ 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.old_applied = false;
branch.applied = false;
self.set_branch(branch)?;
Ok(())
}

View File

@ -253,7 +253,7 @@ pub fn set_base_branch(
order: 0,
selected_for_changes: None,
allow_rebasing: project_repository.project().ok_with_force_push.into(),
old_applied: true,
applied: true,
in_workspace: true,
not_in_workspace_wip_change_id: None,
};

View File

@ -125,7 +125,7 @@ impl<'l> BranchManager<'l> {
order,
selected_for_changes,
allow_rebasing: self.project_repository.project().ok_with_force_push.into(),
old_applied: true,
applied: true,
in_workspace: true,
not_in_workspace_wip_change_id: None,
source_refname: None,
@ -243,7 +243,7 @@ impl<'l> BranchManager<'l> {
branch.order = order;
branch.selected_for_changes = selected_for_changes;
branch.allow_rebasing = self.project_repository.project().ok_with_force_push.into();
branch.old_applied = true;
branch.applied = true;
branch.in_workspace = true;
branch
@ -263,7 +263,7 @@ impl<'l> BranchManager<'l> {
order,
selected_for_changes,
allow_rebasing: self.project_repository.project().ok_with_force_push.into(),
old_applied: true,
applied: true,
in_workspace: true,
not_in_workspace_wip_change_id: None,
}
@ -674,7 +674,10 @@ impl<'l> BranchManager<'l> {
let virtual_branches = vb_state
.list_branches_in_workspace()
.context("failed to read virtual branches")?;
.context("failed to read virtual branches")?
.into_iter()
.filter(|branch| !branch.is_old_unapplied()) // We don't want branches that are unapplied under the old metric to be passed to get_applied_status
.collect();
let (applied_statuses, _) = get_applied_status(
self.project_repository,

View File

@ -350,10 +350,10 @@ fn resolve_old_applied_state(
let branch_manager = project_repository.branch_manager();
for mut branch in branches {
if !branch.old_applied && branch.in_workspace {
if branch.is_old_unapplied() {
branch_manager.convert_to_real_branch(branch.id, Default::default())?;
} else {
branch.old_applied = branch.in_workspace;
branch.applied = branch.in_workspace;
vb_state.set_branch(branch)?;
}
}