Rename Branch to Stack

This commit is contained in:
Kiril Videlov 2024-10-08 15:59:27 +02:00
parent 9e9f3255a8
commit d05d962cf8
38 changed files with 200 additions and 204 deletions

View File

@ -26,13 +26,13 @@ use gitbutler_oplog::{
use gitbutler_project::{FetchResult, Project};
use gitbutler_reference::{ReferenceName, Refname, RemoteRefname};
use gitbutler_repo::{RepoActionsExt, RepositoryExt};
use gitbutler_stack::{BranchId, BranchOwnershipClaims};
use gitbutler_stack::{BranchOwnershipClaims, StackId};
use std::path::PathBuf;
use tracing::instrument;
pub fn create_commit(
project: &Project,
branch_id: BranchId,
branch_id: StackId,
message: &str,
ownership: Option<&BranchOwnershipClaims>,
run_hooks: bool,
@ -91,7 +91,7 @@ pub fn list_virtual_branches_cached(
.map_err(Into::into)
}
pub fn create_virtual_branch(project: &Project, create: &BranchCreateRequest) -> Result<BranchId> {
pub fn create_virtual_branch(project: &Project, create: &BranchCreateRequest) -> Result<StackId> {
let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx).context("Creating a branch requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access();
@ -168,7 +168,7 @@ pub fn push_base_branch(project: &Project, with_force: bool) -> Result<()> {
base::push(&ctx, with_force)
}
pub fn integrate_upstream_commits(project: &Project, branch_id: BranchId) -> Result<()> {
pub fn integrate_upstream_commits(project: &Project, branch_id: StackId) -> Result<()> {
let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx)
.context("Integrating upstream commits requires open workspace mode")?;
@ -234,7 +234,7 @@ pub fn update_branch_order(
Ok(())
}
pub fn unapply_without_saving_virtual_branch(project: &Project, branch_id: BranchId) -> Result<()> {
pub fn unapply_without_saving_virtual_branch(project: &Project, branch_id: StackId) -> Result<()> {
let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx)
.context("Deleting a branch order requires open workspace mode")?;
@ -256,7 +256,7 @@ pub fn unapply_ownership(project: &Project, ownership: &BranchOwnershipClaims) -
vbranch::unapply_ownership(&ctx, ownership, guard.write_permission()).map_err(Into::into)
}
pub fn reset_files(project: &Project, branch_id: BranchId, files: &[PathBuf]) -> Result<()> {
pub fn reset_files(project: &Project, branch_id: StackId, files: &[PathBuf]) -> Result<()> {
let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx).context("Resetting a file requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access();
@ -269,7 +269,7 @@ pub fn reset_files(project: &Project, branch_id: BranchId, files: &[PathBuf]) ->
pub fn amend(
project: &Project,
branch_id: BranchId,
branch_id: StackId,
commit_oid: git2::Oid,
ownership: &BranchOwnershipClaims,
) -> Result<git2::Oid> {
@ -285,7 +285,7 @@ pub fn amend(
pub fn move_commit_file(
project: &Project,
branch_id: BranchId,
branch_id: StackId,
from_commit_oid: git2::Oid,
to_commit_oid: git2::Oid,
ownership: &BranchOwnershipClaims,
@ -301,7 +301,7 @@ pub fn move_commit_file(
.map_err(Into::into)
}
pub fn undo_commit(project: &Project, branch_id: BranchId, commit_oid: git2::Oid) -> Result<()> {
pub fn undo_commit(project: &Project, branch_id: StackId, commit_oid: git2::Oid) -> Result<()> {
let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx).context("Undoing a commit requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access();
@ -322,7 +322,7 @@ pub fn undo_commit(project: &Project, branch_id: BranchId, commit_oid: git2::Oid
pub fn insert_blank_commit(
project: &Project,
branch_id: BranchId,
branch_id: StackId,
commit_oid: git2::Oid,
offset: i32,
) -> Result<()> {
@ -339,7 +339,7 @@ pub fn insert_blank_commit(
pub fn reorder_commit(
project: &Project,
branch_id: BranchId,
branch_id: StackId,
commit_oid: git2::Oid,
offset: i32,
) -> Result<()> {
@ -362,7 +362,7 @@ pub fn reorder_commit(
pub fn reset_virtual_branch(
project: &Project,
branch_id: BranchId,
branch_id: StackId,
target_commit_oid: git2::Oid,
) -> Result<()> {
let ctx = open_with_verify(project)?;
@ -377,7 +377,7 @@ pub fn reset_virtual_branch(
pub fn save_and_unapply_virutal_branch(
project: &Project,
branch_id: BranchId,
branch_id: StackId,
) -> Result<ReferenceName> {
let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx)
@ -400,9 +400,9 @@ pub fn save_and_unapply_virutal_branch(
pub fn push_virtual_branch(
project: &Project,
branch_id: BranchId,
branch_id: StackId,
with_force: bool,
askpass: Option<Option<BranchId>>,
askpass: Option<Option<StackId>>,
) -> Result<vbranch::PushResult> {
let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx).context("Pushing a branch requires open workspace mode")?;
@ -419,7 +419,7 @@ pub fn get_remote_branch_data(project: &Project, refname: &Refname) -> Result<Re
remote::get_branch_data(&ctx, refname)
}
pub fn squash(project: &Project, branch_id: BranchId, commit_oid: git2::Oid) -> Result<()> {
pub fn squash(project: &Project, branch_id: StackId, commit_oid: git2::Oid) -> Result<()> {
let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx).context("Squashing a commit requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access();
@ -432,7 +432,7 @@ pub fn squash(project: &Project, branch_id: BranchId, commit_oid: git2::Oid) ->
pub fn update_commit_message(
project: &Project,
branch_id: BranchId,
branch_id: StackId,
commit_oid: git2::Oid,
message: &str,
) -> Result<()> {
@ -480,7 +480,7 @@ pub fn fetch_from_remotes(project: &Project, askpass: Option<String>) -> Result<
pub fn move_commit(
project: &Project,
target_branch_id: BranchId,
target_branch_id: StackId,
commit_oid: git2::Oid,
) -> Result<()> {
let ctx = open_with_verify(project)?;
@ -499,7 +499,7 @@ pub fn create_virtual_branch_from_branch(
project: &Project,
branch: &Refname,
remote: Option<RemoteRefname>,
) -> Result<BranchId> {
) -> Result<StackId> {
let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx)
.context("Creating a virtual branch from a branch open workspace mode")?;

View File

@ -8,7 +8,7 @@ use gitbutler_error::error::Marker;
use gitbutler_project::{access::WorktreeWritePermission, FetchResult};
use gitbutler_reference::{ReferenceName, Refname, RemoteRefname};
use gitbutler_repo::{rebase::cherry_rebase, LogUntil, RepoActionsExt, RepositoryExt};
use gitbutler_stack::{Branch, BranchOwnershipClaims, Target, VirtualBranchesHandle};
use gitbutler_stack::{BranchOwnershipClaims, Stack, Target, VirtualBranchesHandle};
use serde::Serialize;
use crate::{
@ -231,7 +231,7 @@ pub(crate) fn set_base_branch(
(None, None)
};
let mut branch = Branch::new(
let mut branch = Stack::new(
head_name.to_string().replace("refs/heads/", ""),
Some(head_name),
upstream,
@ -355,7 +355,7 @@ pub(crate) fn update_base_branch(
let updated_vbranches = get_applied_status(ctx, None)?
.branches
.into_iter()
.map(|(mut branch, _)| -> Result<Option<Branch>> {
.map(|(mut branch, _)| -> Result<Option<Stack>> {
let branch_tree = repo.find_tree(branch.tree)?;
let branch_head_commit = repo.find_commit(branch.head()).context(format!(
@ -369,7 +369,7 @@ pub(crate) fn update_base_branch(
branch.id
))?;
let result_integrated_detected = |mut branch: Branch| -> Result<Option<Branch>> {
let result_integrated_detected = |mut branch: Stack| -> Result<Option<Stack>> {
// branch head tree is the same as the new target tree.
// meaning we can safely use the new target commit as the branch head.
@ -455,7 +455,7 @@ pub(crate) fn update_base_branch(
let ok_with_force_push = branch.allow_rebasing;
let result_merge = |mut branch: Branch| -> Result<Option<Branch>> {
let result_merge = |mut branch: Stack| -> Result<Option<Stack>> {
// branch was pushed to upstream, and user doesn't like force pushing.
// create a merge commit to avoid the need of force pushing then.
let branch_head_merge_tree = repo

View File

@ -11,7 +11,7 @@ use gitbutler_project::access::WorktreeReadPermission;
use gitbutler_reference::normalize_branch_name;
use gitbutler_repo::{GixRepositoryExt, RepositoryExt as _};
use gitbutler_serde::BStringForFrontend;
use gitbutler_stack::{Branch as GitButlerBranch, BranchId, Target};
use gitbutler_stack::{Stack as GitButlerBranch, StackId, Target};
use gix::object::tree::diff::Action;
use gix::prelude::ObjectIdExt;
use gix::reference::Category;
@ -437,7 +437,7 @@ pub struct VirtualBranchReference {
/// A non-normalized name of the branch, set by the user
pub given_name: String,
/// Virtual Branch UUID identifier
pub id: BranchId,
pub id: StackId,
/// Determines if the virtual branch is applied in the workspace
pub in_workspace: bool,
}

View File

@ -14,7 +14,7 @@ use gitbutler_repo::{
rebase::{cherry_rebase_group, gitbutler_merge_commits},
LogUntil, RepoActionsExt, RepositoryExt,
};
use gitbutler_stack::{Branch, BranchId, BranchOwnershipClaims};
use gitbutler_stack::{BranchOwnershipClaims, Stack, StackId};
use gitbutler_time::time::now_since_unix_epoch_ms;
use tracing::instrument;
@ -32,7 +32,7 @@ impl BranchManager<'_> {
&self,
create: &BranchCreateRequest,
perm: &mut WorktreeWritePermission,
) -> Result<Branch> {
) -> Result<Stack> {
let vb_state = self.ctx.project().virtual_branches();
let default_target = vb_state.get_default_target()?;
@ -100,7 +100,7 @@ impl BranchManager<'_> {
}
}
let mut branch = Branch::new(
let mut branch = Stack::new(
name.clone(),
None,
None,
@ -128,7 +128,7 @@ impl BranchManager<'_> {
target: &Refname,
upstream_branch: Option<RemoteRefname>,
perm: &mut WorktreeWritePermission,
) -> Result<BranchId> {
) -> Result<StackId> {
// only set upstream if it's not the default target
let upstream_branch = match upstream_branch {
Some(upstream_branch) => Some(upstream_branch),
@ -182,7 +182,7 @@ impl BranchManager<'_> {
.list_branches_in_workspace()
.context("failed to read virtual branches")?
.into_iter()
.collect::<Vec<Branch>>();
.collect::<Vec<Stack>>();
let order = vb_state.next_order_index()?;
@ -235,7 +235,7 @@ impl BranchManager<'_> {
branch
} else {
let upstream_head = upstream_branch.is_some().then_some(head_commit.id());
Branch::new(
Stack::new(
branch_name.clone(),
Some(target.clone()),
upstream_branch,
@ -271,7 +271,7 @@ impl BranchManager<'_> {
#[instrument(level = tracing::Level::DEBUG, skip(self, perm), err(Debug))]
fn apply_branch(
&self,
branch_id: BranchId,
branch_id: StackId,
perm: &mut WorktreeWritePermission,
) -> Result<String> {
self.ctx.assure_resolved()?;

View File

@ -8,7 +8,7 @@ use gitbutler_oplog::SnapshotExt;
use gitbutler_project::access::WorktreeWritePermission;
use gitbutler_reference::{normalize_branch_name, ReferenceName, Refname};
use gitbutler_repo::{RepoActionsExt, RepositoryExt};
use gitbutler_stack::{Branch, BranchId};
use gitbutler_stack::{Stack, StackId};
use tracing::instrument;
use super::BranchManager;
@ -25,7 +25,7 @@ impl BranchManager<'_> {
#[instrument(level = tracing::Level::DEBUG, skip(self, perm), err(Debug))]
pub fn save_and_unapply(
&self,
branch_id: BranchId,
branch_id: StackId,
perm: &mut WorktreeWritePermission,
) -> Result<ReferenceName> {
let vb_state = self.ctx.project().virtual_branches();
@ -55,7 +55,7 @@ impl BranchManager<'_> {
#[instrument(level = tracing::Level::DEBUG, skip(self, perm), err(Debug))]
pub(crate) fn unapply_without_saving(
&self,
branch_id: BranchId,
branch_id: StackId,
perm: &mut WorktreeWritePermission,
target_commit: &Commit,
) -> Result<()> {
@ -146,7 +146,7 @@ impl BranchManager<'_> {
impl BranchManager<'_> {
#[instrument(level = tracing::Level::DEBUG, skip(self, vbranch), err(Debug))]
fn build_real_branch(&self, vbranch: &mut Branch) -> Result<git2::Branch<'_>> {
fn build_real_branch(&self, vbranch: &mut Stack) -> Result<git2::Branch<'_>> {
let repo = self.ctx.repository();
let target_commit = repo.find_commit(vbranch.head())?;
let branch_name = vbranch.name.clone();
@ -164,7 +164,7 @@ impl BranchManager<'_> {
fn build_wip_commit(
&self,
vbranch: &mut Branch,
vbranch: &mut Stack,
branch: &git2::Branch<'_>,
) -> Result<Option<git2::Oid>> {
let repo = self.ctx.repository();

View File

@ -5,7 +5,7 @@ use gitbutler_commit::commit_ext::CommitExt as _;
use gitbutler_project::access::WorktreeWritePermission;
use gitbutler_repo::rebase::cherry_rebase_group;
use gitbutler_repo::RepositoryExt as _;
use gitbutler_stack::Branch;
use gitbutler_stack::Stack;
use crate::VirtualBranchesExt as _;
@ -86,7 +86,7 @@ pub struct BranchHeadAndTree {
/// mutated the virtual_branches.toml.
pub fn compute_updated_branch_head(
repository: &git2::Repository,
branch: &Branch,
branch: &Stack,
new_head: git2::Oid,
fearless_rebasing: bool,
) -> Result<BranchHeadAndTree> {

View File

@ -6,7 +6,7 @@ use anyhow::{Context, Result};
use gitbutler_command_context::CommandContext;
use gitbutler_commit::commit_ext::CommitExt;
use gitbutler_serde::BStringForFrontend;
use gitbutler_stack::{Branch, BranchId};
use gitbutler_stack::{Stack, StackId};
use serde::Serialize;
// this is the struct that maps to the view `Commit` type in Typescript
@ -30,7 +30,7 @@ pub struct VirtualBranchCommit {
pub is_integrated: bool,
#[serde(with = "gitbutler_serde::oid_vec")]
pub parent_ids: Vec<git2::Oid>,
pub branch_id: BranchId,
pub branch_id: StackId,
pub change_id: Option<String>,
pub is_signed: bool,
pub conflicted: bool,
@ -43,7 +43,7 @@ pub struct VirtualBranchCommit {
pub(crate) fn commit_to_vbranch_commit(
ctx: &CommandContext,
branch: &Branch,
branch: &Stack,
commit: &git2::Commit,
is_integrated: bool,
is_remote: bool,

View File

@ -7,7 +7,7 @@ use std::{
use gitbutler_diff::{GitHunk, Hunk, HunkHash};
use gitbutler_serde::BStringForFrontend;
use gitbutler_stack::BranchId;
use gitbutler_stack::StackId;
use itertools::Itertools;
use md5::Digest;
use serde::Serialize;
@ -48,7 +48,7 @@ pub struct VirtualBranchHunk {
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Copy)]
#[serde(rename_all = "camelCase")]
pub struct HunkLock {
pub branch_id: BranchId,
pub branch_id: StackId,
#[serde(with = "gitbutler_serde::oid")]
pub commit_id: git2::Oid,
}

View File

@ -11,7 +11,7 @@ use gitbutler_error::error::Marker;
use gitbutler_operating_modes::OPEN_WORKSPACE_REFS;
use gitbutler_project::access::WorktreeWritePermission;
use gitbutler_repo::{LogUntil, RepositoryExt};
use gitbutler_stack::{Branch, VirtualBranchesHandle};
use gitbutler_stack::{Stack, VirtualBranchesHandle};
use tracing::instrument;
use crate::{branch_manager::BranchManagerExt, conflicts, VirtualBranchesExt};
@ -36,7 +36,7 @@ pub(crate) fn get_workspace_head(ctx: &CommandContext) -> Result<git2::Oid> {
.context("failed to get target")?;
let repo: &git2::Repository = ctx.repository();
let mut virtual_branches: Vec<Branch> = vb_state.list_branches_in_workspace()?;
let mut virtual_branches: Vec<Stack> = vb_state.list_branches_in_workspace()?;
let target_commit = repo.find_commit(target.sha)?;
let mut workspace_tree = repo.find_real_tree(&target_commit, Default::default())?;
@ -152,7 +152,7 @@ pub fn update_workspace_commit(
let vb_state = ctx.project().virtual_branches();
// get all virtual branches, we need to try to update them all
let virtual_branches: Vec<Branch> = vb_state
let virtual_branches: Vec<Stack> = vb_state
.list_branches_in_workspace()
.context("failed to list virtual branches")?;

View File

@ -7,13 +7,13 @@ use gitbutler_command_context::CommandContext;
use gitbutler_commit::commit_ext::CommitExt;
use gitbutler_project::access::WorktreeWritePermission;
use gitbutler_repo::{rebase::cherry_rebase_group, LogUntil, RepositoryExt};
use gitbutler_stack::{BranchId, OwnershipClaim};
use gitbutler_stack::{OwnershipClaim, StackId};
use std::collections::HashMap;
/// moves commit from the branch it's in to the top of the target branch
pub(crate) fn move_commit(
ctx: &CommandContext,
target_branch_id: BranchId,
target_branch_id: StackId,
commit_id: git2::Oid,
perm: &mut WorktreeWritePermission,
) -> Result<()> {

View File

@ -2,7 +2,7 @@ use anyhow::{bail, Context as _, Result};
use gitbutler_command_context::CommandContext;
use gitbutler_project::access::WorktreeWritePermission;
use gitbutler_repo::{rebase::cherry_rebase_group, LogUntil, RepositoryExt as _};
use gitbutler_stack::BranchId;
use gitbutler_stack::StackId;
use crate::{
branch_trees::{
@ -38,7 +38,7 @@ use crate::{
/// D
pub(crate) fn reorder_commit(
ctx: &CommandContext,
branch_id: BranchId,
branch_id: StackId,
subject_commit_oid: git2::Oid,
offset: i32,
perm: &mut WorktreeWritePermission,

View File

@ -2,8 +2,8 @@ use anyhow::{Context, Result};
use gitbutler_commit::commit_ext::CommitExt;
use gitbutler_patch_reference::{CommitOrChangeId, PatchReference};
use gitbutler_project::Project;
use gitbutler_stack::BranchId;
use gitbutler_stack_api::{PatchReferenceUpdate, Stack};
use gitbutler_stack::StackId;
use gitbutler_stack_api::{PatchReferenceUpdate, StackActions};
use serde::{Deserialize, Serialize};
use crate::{actions::open_with_verify, VirtualBranchesExt};
@ -22,7 +22,7 @@ use gitbutler_operating_modes::assure_open_workspace_mode;
/// The argument `preceding_head` is only used if there are multiple heads that point to the same patch, otherwise it is ignored.
pub fn create_series(
project: &Project,
branch_id: BranchId,
branch_id: StackId,
req: CreateSeriesRequest,
) -> Result<()> {
let ctx = &open_with_verify(project)?;
@ -62,7 +62,7 @@ pub struct CreateSeriesRequest {
/// The very last branch (reference) cannot be removed (A Stack must always contains at least one reference)
/// If there were commits/changes that were *only* referenced by the removed branch,
/// those commits are moved to the branch underneath it (or more accurately, the precee)
pub fn remove_series(project: &Project, branch_id: BranchId, head_name: String) -> Result<()> {
pub fn remove_series(project: &Project, branch_id: StackId, head_name: String) -> Result<()> {
let ctx = &open_with_verify(project)?;
assure_open_workspace_mode(ctx).context("Requires an open workspace mode")?;
let mut stack = ctx.project().virtual_branches().get_branch(branch_id)?;
@ -74,7 +74,7 @@ pub fn remove_series(project: &Project, branch_id: BranchId, head_name: String)
/// If the series have been pushed to a remote, the name can not be changed as it corresponds to a remote ref.
pub fn update_series_name(
project: &Project,
branch_id: BranchId,
branch_id: StackId,
head_name: String,
new_head_name: String,
) -> Result<()> {
@ -95,7 +95,7 @@ pub fn update_series_name(
/// The description can be set to `None` to remove it.
pub fn update_series_description(
project: &Project,
branch_id: BranchId,
branch_id: StackId,
head_name: String,
description: Option<String>,
) -> Result<()> {
@ -114,7 +114,7 @@ pub fn update_series_description(
/// Pushes all series in the stack to the remote.
/// This operation will error out if the target has no push remote configured.
pub fn push_stack(project: &Project, branch_id: BranchId, with_force: bool) -> Result<()> {
pub fn push_stack(project: &Project, branch_id: StackId, with_force: bool) -> Result<()> {
let ctx = &open_with_verify(project)?;
assure_open_workspace_mode(ctx).context("Requires an open workspace mode")?;
let state = ctx.project().virtual_branches();

View File

@ -15,15 +15,15 @@ use gitbutler_command_context::CommandContext;
use gitbutler_diff::{diff_files_into_hunks, GitHunk, Hunk, HunkHash};
use gitbutler_operating_modes::assure_open_workspace_mode;
use gitbutler_project::access::WorktreeWritePermission;
use gitbutler_stack::{Branch, BranchId, BranchOwnershipClaims, OwnershipClaim};
use gitbutler_stack_api::Stack;
use gitbutler_stack::{BranchOwnershipClaims, OwnershipClaim, Stack, StackId};
use gitbutler_stack_api::StackActions;
use tracing::instrument;
/// Represents the uncommitted status of the applied virtual branches in the workspace.
#[derive(Debug)]
pub struct VirtualBranchesStatus {
/// A collection of branches and their associated uncommitted file changes.
pub branches: Vec<(Branch, Vec<VirtualBranchFile>)>,
pub branches: Vec<(Stack, Vec<VirtualBranchFile>)>,
/// A collection of files that were skipped during the diffing process (due to being very large and unprocessable).
pub skipped_files: Vec<gitbutler_diff::FileDiff>,
}
@ -84,7 +84,7 @@ pub fn get_applied_status_cached(
}
}
let mut diffs_by_branch: HashMap<BranchId, HashMap<PathBuf, Vec<gitbutler_diff::GitHunk>>> =
let mut diffs_by_branch: HashMap<StackId, HashMap<PathBuf, Vec<gitbutler_diff::GitHunk>>> =
virtual_branches
.iter()
.map(|branch| (branch.id, HashMap::new()))
@ -223,7 +223,7 @@ pub fn get_applied_status_cached(
.context(format!("failed to write virtual branch {}", vbranch.name))?;
}
}
let hunks_by_branch: Vec<(Branch, HashMap<PathBuf, Vec<VirtualBranchHunk>>)> = hunks_by_branch
let hunks_by_branch: Vec<(Stack, HashMap<PathBuf, Vec<VirtualBranchHunk>>)> = hunks_by_branch
.iter()
.map(|(branch, hunks)| {
let hunks = file_hunks_from_diffs(&ctx.project().path, hunks.clone(), Some(&locks));
@ -231,7 +231,7 @@ pub fn get_applied_status_cached(
})
.collect();
let files_by_branch: Vec<(Branch, Vec<VirtualBranchFile>)> = hunks_by_branch
let files_by_branch: Vec<(Stack, Vec<VirtualBranchFile>)> = hunks_by_branch
.iter()
.map(|(branch, hunks)| {
let files = virtual_hunks_into_virtual_files(ctx, hunks.clone());
@ -248,7 +248,7 @@ pub fn get_applied_status_cached(
fn compute_locks(
repository: &git2::Repository,
unstaged_hunks_by_path: &HashMap<PathBuf, Vec<gitbutler_diff::GitHunk>>,
virtual_branches: &[Branch],
virtual_branches: &[Stack],
base_tree: Tree,
) -> Result<HashMap<HunkHash, Vec<HunkLock>>> {
let mut diff_opts = git2::DiffOptions::new();
@ -275,7 +275,7 @@ fn compute_locks(
.collect::<Vec<_>>();
let mut workspace_hunks_by_path =
HashMap::<PathBuf, Vec<(gitbutler_diff::GitHunk, &Branch)>>::new();
HashMap::<PathBuf, Vec<(gitbutler_diff::GitHunk, &Stack)>>::new();
for (branch, hunks_by_filepath) in branch_path_diffs {
for (path, hunks) in hunks_by_filepath {

View File

@ -2,7 +2,7 @@ use anyhow::{bail, Context as _, Result};
use gitbutler_command_context::CommandContext;
use gitbutler_commit::commit_ext::CommitExt as _;
use gitbutler_repo::{rebase::cherry_rebase_group, LogUntil, RepositoryExt as _};
use gitbutler_stack::{Branch, BranchId};
use gitbutler_stack::{Stack, StackId};
use crate::VirtualBranchesExt as _;
@ -19,9 +19,9 @@ use crate::VirtualBranchesExt as _;
/// undone.
pub(crate) fn undo_commit(
ctx: &CommandContext,
branch_id: BranchId,
branch_id: StackId,
commit_oid: git2::Oid,
) -> Result<Branch> {
) -> Result<Stack> {
let vb_state = ctx.project().virtual_branches();
let succeeding_rebases = ctx.project().succeeding_rebases;

View File

@ -6,7 +6,7 @@ use gitbutler_repo::{
rebase::{cherry_rebase_group, gitbutler_merge_commits},
LogUntil, RepoActionsExt as _, RepositoryExt as _,
};
use gitbutler_stack::{Branch, BranchId, Target, VirtualBranchesHandle};
use gitbutler_stack::{Stack, StackId, Target, VirtualBranchesHandle};
use serde::{Deserialize, Serialize};
use crate::{
@ -29,7 +29,7 @@ pub enum BranchStatus {
#[serde(tag = "type", content = "subject", rename_all = "camelCase")]
pub enum BranchStatuses {
UpToDate,
UpdatesRequired(Vec<(BranchId, BranchStatus)>),
UpdatesRequired(Vec<(StackId, BranchStatus)>),
}
#[derive(Serialize, Deserialize, PartialEq, Debug)]
@ -74,7 +74,7 @@ impl BranchStatus {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Resolution {
branch_id: BranchId,
branch_id: StackId,
/// Used to ensure a given branch hasn't changed since the UI issued the command.
#[serde(with = "gitbutler_serde::oid")]
branch_tree: git2::Oid,
@ -90,7 +90,7 @@ enum IntegrationResult {
pub struct UpstreamIntegrationContext<'a> {
_permission: Option<&'a mut WorktreeWritePermission>,
repository: &'a git2::Repository,
virtual_branches_in_workspace: Vec<Branch>,
virtual_branches_in_workspace: Vec<Stack>,
new_target: git2::Commit<'a>,
old_target: git2::Commit<'a>,
target_branch_name: String,
@ -391,7 +391,7 @@ fn compute_resolutions(
context: &UpstreamIntegrationContext,
resolutions: &[Resolution],
base_branch_resolution_approach: Option<BaseBranchResolutionApproach>,
) -> Result<Vec<(BranchId, IntegrationResult)>> {
) -> Result<Vec<(StackId, IntegrationResult)>> {
let UpstreamIntegrationContext {
repository,
new_target,
@ -502,8 +502,8 @@ mod test {
use super::*;
fn make_branch(head: git2::Oid, tree: git2::Oid) -> Branch {
let mut branch = Branch::new(
fn make_branch(head: git2::Oid, tree: git2::Oid) -> Stack {
let mut branch = Stack::new(
"branchy branch".into(),
None,
None,

View File

@ -27,9 +27,9 @@ use gitbutler_repo::{
LogUntil, RepoActionsExt, RepositoryExt,
};
use gitbutler_stack::{
reconcile_claims, Branch, BranchId, BranchOwnershipClaims, Target, VirtualBranchesHandle,
reconcile_claims, BranchOwnershipClaims, Stack, StackId, Target, VirtualBranchesHandle,
};
use gitbutler_stack_api::{commit_by_oid_or_change_id, Stack};
use gitbutler_stack_api::{commit_by_oid_or_change_id, StackActions};
use gitbutler_time::time::now_since_unix_epoch_ms;
use serde::Serialize;
use std::collections::HashSet;
@ -47,7 +47,7 @@ use tracing::instrument;
#[serde(rename_all = "camelCase")]
#[allow(clippy::struct_excessive_bools)]
pub struct VirtualBranch {
pub id: BranchId,
pub id: StackId,
pub name: String,
pub notes: String,
pub active: bool,
@ -209,7 +209,7 @@ pub fn unapply_ownership(
// reset a file in the project to the index state
pub(crate) fn reset_files(
ctx: &CommandContext,
branch_id: BranchId,
branch_id: StackId,
files: &[PathBuf],
perm: &mut WorktreeWritePermission,
) -> Result<()> {
@ -469,7 +469,7 @@ pub fn list_virtual_branches_cached(
/// Newest first, oldest last in the list
fn stack_series(
ctx: &CommandContext,
branch: &Branch,
branch: &Stack,
default_target: &Target,
check_commit: &IsCommitIntegrated,
) -> Result<Vec<PatchSeries>> {
@ -563,7 +563,7 @@ fn branches_with_large_files_abridged(mut branches: Vec<VirtualBranch>) -> Vec<V
branches
}
fn is_requires_force(ctx: &CommandContext, branch: &Branch) -> Result<bool> {
fn is_requires_force(ctx: &CommandContext, branch: &Stack) -> Result<bool> {
let upstream = if let Some(upstream) = &branch.upstream {
upstream
} else {
@ -613,7 +613,7 @@ fn is_requires_force(ctx: &CommandContext, branch: &Branch) -> Result<bool> {
/// might introduce more conflicts, but there is no need to commit at the
/// end since there will only be one parent commit.
///
pub fn integrate_upstream_commits(ctx: &CommandContext, branch_id: BranchId) -> Result<()> {
pub fn integrate_upstream_commits(ctx: &CommandContext, branch_id: StackId) -> Result<()> {
conflicts::is_conflicting(ctx, None)?;
let repo = ctx.repository();
@ -733,7 +733,7 @@ pub fn integrate_upstream_commits(ctx: &CommandContext, branch_id: BranchId) ->
pub(crate) fn integrate_with_rebase(
ctx: &CommandContext,
branch: &mut Branch,
branch: &mut Stack,
unknown_commits: &mut Vec<git2::Oid>,
) -> Result<git2::Oid> {
cherry_rebase_group(
@ -746,7 +746,7 @@ pub(crate) fn integrate_with_rebase(
pub(crate) fn integrate_with_merge(
ctx: &CommandContext,
branch: &mut Branch,
branch: &mut Stack,
upstream_commit: &git2::Commit,
merge_base: git2::Oid,
) -> Result<git2::Oid> {
@ -794,7 +794,7 @@ pub(crate) fn integrate_with_merge(
)
}
pub fn update_branch(ctx: &CommandContext, branch_update: &BranchUpdateRequest) -> Result<Branch> {
pub fn update_branch(ctx: &CommandContext, branch_update: &BranchUpdateRequest) -> Result<Stack> {
let vb_state = ctx.project().virtual_branches();
let mut branch = vb_state.get_branch_in_workspace(branch_update.id)?;
@ -898,7 +898,7 @@ pub(crate) fn ensure_selected_for_changes(vb_state: &VirtualBranchesHandle) -> R
pub(crate) fn set_ownership(
vb_state: &VirtualBranchesHandle,
target_branch: &mut Branch,
target_branch: &mut Stack,
ownership: &BranchOwnershipClaims,
) -> Result<()> {
if target_branch.ownership.eq(ownership) {
@ -932,7 +932,7 @@ pub type VirtualBranchHunksByPathMap = HashMap<PathBuf, Vec<VirtualBranchHunk>>;
// reset virtual branch to a specific commit
pub(crate) fn reset_branch(
ctx: &CommandContext,
branch_id: BranchId,
branch_id: StackId,
target_commit_id: git2::Oid,
) -> Result<()> {
let vb_state = ctx.project().virtual_branches();
@ -1005,7 +1005,7 @@ pub(crate) fn reset_branch(
#[allow(clippy::too_many_arguments)]
pub fn commit(
ctx: &CommandContext,
branch_id: BranchId,
branch_id: StackId,
message: &str,
ownership: Option<&BranchOwnershipClaims>,
run_hooks: bool,
@ -1139,9 +1139,9 @@ pub fn commit(
pub(crate) fn push(
ctx: &CommandContext,
branch_id: BranchId,
branch_id: StackId,
with_force: bool,
askpass: Option<Option<BranchId>>,
askpass: Option<Option<StackId>>,
) -> Result<PushResult> {
let vb_state = ctx.project().virtual_branches();
@ -1324,7 +1324,7 @@ pub fn is_remote_branch_mergeable(
// then added to the "to" commit and everything above that rebased again.
pub(crate) fn move_commit_file(
ctx: &CommandContext,
branch_id: BranchId,
branch_id: StackId,
from_commit_id: git2::Oid,
to_commit_id: git2::Oid,
target_ownership: &BranchOwnershipClaims,
@ -1562,7 +1562,7 @@ pub(crate) fn move_commit_file(
// and the respective branch head is updated
pub(crate) fn amend(
ctx: &CommandContext,
branch_id: BranchId,
branch_id: StackId,
commit_oid: git2::Oid,
target_ownership: &BranchOwnershipClaims,
) -> Result<git2::Oid> {
@ -1689,7 +1689,7 @@ pub(crate) fn amend(
// return the oid of the new head commit of the branch with the inserted blank commit
pub(crate) fn insert_blank_commit(
ctx: &CommandContext,
branch_id: BranchId,
branch_id: StackId,
commit_oid: git2::Oid,
offset: i32,
) -> Result<()> {
@ -1739,11 +1739,7 @@ pub(crate) fn insert_blank_commit(
}
/// squashes a commit from a virtual branch into its parent.
pub(crate) fn squash(
ctx: &CommandContext,
branch_id: BranchId,
commit_id: git2::Oid,
) -> Result<()> {
pub(crate) fn squash(ctx: &CommandContext, branch_id: StackId, commit_id: git2::Oid) -> Result<()> {
ctx.assure_resolved()?;
let vb_state = ctx.project().virtual_branches();
@ -1843,7 +1839,7 @@ pub(crate) fn squash(
// changes a commit message for commit_oid, rebases everything above it, updates branch head if successful
pub(crate) fn update_commit_message(
ctx: &CommandContext,
branch_id: BranchId,
branch_id: StackId,
commit_id: git2::Oid,
message: &str,
) -> Result<()> {

View File

@ -1,11 +1,11 @@
use gitbutler_stack::Branch;
use gitbutler_stack::Stack;
/// Makes a Branch struct with a bunch of default values.
///
/// This assumes that the only relevant properties for your test are the head
/// and tree Oids.
fn make_branch(head: git2::Oid, tree: git2::Oid) -> Branch {
let mut branch = Branch::new(
fn make_branch(head: git2::Oid, tree: git2::Oid) -> Stack {
let mut branch = Stack::new(
"branchy branch".into(),
None,
None,

View File

@ -1,7 +1,7 @@
use gitbutler_branch::{BranchCreateRequest, BranchUpdateRequest};
use gitbutler_branch_actions::VirtualBranch;
use gitbutler_id::id::Id;
use gitbutler_stack::Branch;
use gitbutler_stack::Stack;
use super::*;
@ -120,7 +120,7 @@ fn commit_and_push_initial(repository: &TestProject) {
repository.push();
}
fn get_virtual_branch(project: &Project, branch_id: Id<Branch>) -> VirtualBranch {
fn get_virtual_branch(project: &Project, branch_id: Id<Stack>) -> VirtualBranch {
gitbutler_branch_actions::list_virtual_branches(project)
.unwrap()
.0

View File

@ -1,6 +1,6 @@
use bstr::ByteSlice;
use gitbutler_branch::BranchCreateRequest;
use gitbutler_stack::BranchId;
use gitbutler_stack::StackId;
use std::{path::PathBuf, str::FromStr};
use super::Test;
@ -654,7 +654,7 @@ fn no_branch() {
gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
.unwrap();
let id = BranchId::generate();
let id = StackId::generate();
assert_eq!(
gitbutler_branch_actions::move_commit(project, id, commit_oid)
.unwrap_err()

View File

@ -1,11 +1,11 @@
use bstr::{BStr, ByteSlice};
use gitbutler_stack::{BranchId, BranchOwnershipClaims};
use gitbutler_stack::{BranchOwnershipClaims, StackId};
use serde::{Deserialize, Serialize, Serializer};
use std::ops::Deref;
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct BranchUpdateRequest {
pub id: BranchId,
pub id: StackId,
pub name: Option<String>,
pub notes: Option<String>,
pub ownership: Option<BranchOwnershipClaims>,

View File

@ -1,7 +1,7 @@
use gitbutler_reference::ReferenceName;
use serde::{Deserialize, Serialize};
use gitbutler_stack::BranchId;
use gitbutler_stack::StackId;
/// GitButler reference associated with a change (commit) on a virtual branch.
/// These are not the same as regular Git references, but rather app-managed refs.
@ -11,7 +11,7 @@ use gitbutler_stack::BranchId;
pub struct ChangeReference {
/// Branch id of the virtual branch this reference belongs to
/// Multiple references may belong to the same virtual branch, representing separate deployable / reviewable parts of the vbranch.
pub branch_id: BranchId,
pub branch_id: StackId,
/// Fully qualified reference name.
/// The reference must be a remote reference.
pub name: ReferenceName,

View File

@ -3,7 +3,7 @@ use gitbutler_branch::{BranchCreateRequest, BranchIdentity, BranchUpdateRequest}
use gitbutler_branch_actions::{get_branch_listing_details, list_branches};
use gitbutler_command_context::CommandContext;
use gitbutler_project::Project;
use gitbutler_stack::{Branch, VirtualBranchesHandle};
use gitbutler_stack::{Stack, VirtualBranchesHandle};
use crate::command::debug_print;
@ -78,7 +78,7 @@ pub fn set_default(project: Project, branch_name: String) -> Result<()> {
set_default_branch(&project, &branch)
}
fn set_default_branch(project: &Project, branch: &Branch) -> Result<()> {
fn set_default_branch(project: &Project, branch: &Stack) -> Result<()> {
gitbutler_branch_actions::update_virtual_branch(
project,
BranchUpdateRequest {
@ -143,7 +143,7 @@ pub fn commit(project: Project, branch_name: String, message: String) -> Result<
)?)
}
pub fn branch_by_name(project: &Project, name: &str) -> Result<Branch> {
pub fn branch_by_name(project: &Project, name: &str) -> Result<Stack> {
let mut found: Vec<_> = VirtualBranchesHandle::new(project.gb_dir())
.list_all_branches()?
.into_iter()

View File

@ -23,7 +23,7 @@ use gitbutler_operating_modes::{
use gitbutler_project::access::{WorktreeReadPermission, WorktreeWritePermission};
use gitbutler_reference::{ReferenceName, Refname};
use gitbutler_repo::{rebase::cherry_rebase, RepositoryExt};
use gitbutler_stack::{Branch, VirtualBranchesHandle};
use gitbutler_stack::{Stack, VirtualBranchesHandle};
pub mod commands;
@ -112,7 +112,7 @@ fn checkout_edit_branch(ctx: &CommandContext, commit: &git2::Commit) -> Result<(
fn find_virtual_branch_by_reference(
ctx: &CommandContext,
reference: &ReferenceName,
) -> Result<Option<Branch>> {
) -> Result<Option<Stack>> {
let vb_state = VirtualBranchesHandle::new(ctx.project().gb_dir());
let all_virtual_branches = vb_state
.list_branches_in_workspace()

View File

@ -16,7 +16,7 @@ use gitbutler_project::{
Project,
};
use gitbutler_repo::RepositoryExt;
use gitbutler_stack::{Branch, VirtualBranchesHandle, VirtualBranchesState};
use gitbutler_stack::{Stack, VirtualBranchesHandle, VirtualBranchesState};
use tracing::instrument;
use super::{
@ -732,7 +732,7 @@ fn lines_since_snapshot(project: &Project, repo: &git2::Repository) -> Result<us
#[instrument(level = tracing::Level::DEBUG, skip(branch, repo), err(Debug))]
fn branch_lines_since_snapshot(
branch: &Branch,
branch: &Stack,
repo: &git2::Repository,
head_sha: git2::Oid,
) -> Result<usize> {

View File

@ -4,7 +4,7 @@ use anyhow::Result;
use gitbutler_branch::BranchUpdateRequest;
use gitbutler_project::{access::WorktreeWritePermission, Project};
use gitbutler_reference::ReferenceName;
use gitbutler_stack::Branch;
use gitbutler_stack::Stack;
use super::entry::Trailer;
use crate::{
@ -50,7 +50,7 @@ pub trait SnapshotExt {
fn snapshot_branch_update(
&self,
snapshot_tree: git2::Oid,
old_branch: &Branch,
old_branch: &Stack,
update: &BranchUpdateRequest,
error: Option<&anyhow::Error>,
perm: &mut WorktreeWritePermission,
@ -141,7 +141,7 @@ impl SnapshotExt for Project {
fn snapshot_branch_update(
&self,
snapshot_tree: git2::Oid,
old_branch: &Branch,
old_branch: &Stack,
update: &BranchUpdateRequest,
error: Option<&anyhow::Error>,
perm: &mut WorktreeWritePermission,

View File

@ -1,7 +1,7 @@
use std::{collections::HashMap, path::Path, sync::Arc};
use gitbutler_id::id::Id;
use gitbutler_stack::BranchId;
use gitbutler_stack::StackId;
use serde::Serialize;
use tokio::sync::{oneshot, Mutex};
@ -38,9 +38,9 @@ pub struct AskpassRequest {
// This is needed to end up with a struct with either `branch_id` or `action`
#[serde(untagged)]
pub enum Context {
Push { branch_id: Option<BranchId> },
Push { branch_id: Option<StackId> },
Fetch { action: String },
SignedCommit { branch_id: Option<BranchId> },
SignedCommit { branch_id: Option<StackId> },
}
#[derive(Clone)]
@ -89,7 +89,7 @@ impl AskpassBroker {
async fn handle_git_prompt_commit_sign_sync(
prompt: String,
branch_id: Option<BranchId>,
branch_id: Option<StackId>,
) -> Option<String> {
tracing::info!("received prompt for synchronous signed commit {branch_id:?}: {prompt:?}");
get_broker()
@ -103,7 +103,7 @@ async fn handle_git_prompt_commit_sign_sync(
pub fn sign_commit_sync(
repo_path: impl AsRef<Path>,
base_commitish: impl AsRef<str>,
branch_id: Option<BranchId>,
branch_id: Option<StackId>,
) -> Result<String, impl std::error::Error> {
let repo_path = repo_path.as_ref().to_path_buf();
let base_commitish: &str = base_commitish.as_ref();

View File

@ -6,7 +6,7 @@ use gitbutler_commit::commit_headers::CommitHeadersV2;
use gitbutler_error::error::Code;
use gitbutler_project::AuthKey;
use gitbutler_reference::{Refname, RemoteRefname};
use gitbutler_stack::{Branch, BranchId};
use gitbutler_stack::{Stack, StackId};
use crate::{askpass, credentials, RepositoryExt};
pub trait RepoActionsExt {
@ -17,7 +17,7 @@ pub trait RepoActionsExt {
branch: &RemoteRefname,
with_force: bool,
refspec: Option<String>,
askpass_broker: Option<Option<BranchId>>,
askpass_broker: Option<Option<StackId>>,
) -> Result<()>;
fn commit(
&self,
@ -27,13 +27,13 @@ pub trait RepoActionsExt {
commit_headers: Option<CommitHeadersV2>,
) -> Result<git2::Oid>;
fn distance(&self, from: git2::Oid, to: git2::Oid) -> Result<u32>;
fn delete_branch_reference(&self, branch: &Branch) -> Result<()>;
fn add_branch_reference(&self, branch: &Branch) -> Result<()>;
fn delete_branch_reference(&self, branch: &Stack) -> Result<()>;
fn add_branch_reference(&self, branch: &Stack) -> Result<()>;
fn git_test_push(
&self,
remote_name: &str,
branch_name: &str,
askpass: Option<Option<BranchId>>,
askpass: Option<Option<StackId>>,
) -> Result<()>;
}
@ -42,7 +42,7 @@ impl RepoActionsExt for CommandContext {
&self,
remote_name: &str,
branch_name: &str,
askpass: Option<Option<BranchId>>,
askpass: Option<Option<StackId>>,
) -> Result<()> {
let target_branch_refname =
Refname::from_str(&format!("refs/remotes/{}/{}", remote_name, branch_name))?;
@ -73,7 +73,7 @@ impl RepoActionsExt for CommandContext {
Ok(())
}
fn add_branch_reference(&self, branch: &Branch) -> Result<()> {
fn add_branch_reference(&self, branch: &Stack) -> Result<()> {
let (should_write, with_force) = match self
.repository()
.find_reference(&branch.refname()?.to_string())
@ -103,7 +103,7 @@ impl RepoActionsExt for CommandContext {
Ok(())
}
fn delete_branch_reference(&self, branch: &Branch) -> Result<()> {
fn delete_branch_reference(&self, branch: &Stack) -> Result<()> {
match self
.repository()
.find_reference(&branch.refname()?.to_string())
@ -158,7 +158,7 @@ impl RepoActionsExt for CommandContext {
branch: &RemoteRefname,
with_force: bool,
refspec: Option<String>,
askpass_broker: Option<Option<BranchId>>,
askpass_broker: Option<Option<StackId>>,
) -> Result<()> {
let refspec = refspec.unwrap_or_else(|| {
if with_force {
@ -335,7 +335,7 @@ pub enum LogUntil {
async fn handle_git_prompt_push(
prompt: String,
askpass: Option<Option<BranchId>>,
askpass: Option<Option<StackId>>,
) -> Option<String> {
if let Some(branch_id) = askpass {
tracing::info!("received prompt for branch push {branch_id:?}: {prompt:?}");

View File

@ -2,4 +2,4 @@ mod heads;
mod series;
mod stack;
pub use series::Series;
pub use stack::{commit_by_oid_or_change_id, PatchReferenceUpdate, Stack, TargetUpdate};
pub use stack::{commit_by_oid_or_change_id, PatchReferenceUpdate, StackActions, TargetUpdate};

View File

@ -12,7 +12,7 @@ use gitbutler_reference::RemoteRefname;
use gitbutler_repo::LogUntil;
use gitbutler_repo::RepoActionsExt;
use gitbutler_repo::RepositoryExt;
use gitbutler_stack::Branch;
use gitbutler_stack::Stack;
use gitbutler_stack::Target;
use gitbutler_stack::VirtualBranchesHandle;
use gix::validate::reference::name_partial;
@ -30,7 +30,7 @@ use crate::series::Series;
/// - have at least one head (branch)
/// - include only referecences that are part of the stack
/// - always have it's commits under a reference i.e. no orphaned commits
pub trait Stack {
pub trait StackActions {
/// An initialized stack has at least one head (branch).
fn initialized(&self) -> bool;
@ -139,7 +139,7 @@ pub struct TargetUpdate {
/// The first patches are in the beginning of the list and the most recent patches are at the end of the list (top of the stack)
/// Similarly, heads that point to earlier commits are first in the order, and the last head always points to the most recent patch.
/// If there are multiple heads that point to the same patch, the `add` and `update` operations can specify the intended order.
impl Stack for Branch {
impl StackActions for Stack {
fn initialized(&self) -> bool {
!self.heads.is_empty()
}

View File

@ -4,7 +4,7 @@ use gitbutler_commit::commit_ext::CommitExt;
use gitbutler_patch_reference::{CommitOrChangeId, PatchReference};
use gitbutler_repo::{LogUntil, RepositoryExt as _};
use gitbutler_stack::VirtualBranchesHandle;
use gitbutler_stack_api::{PatchReferenceUpdate, Stack, TargetUpdate};
use gitbutler_stack_api::{PatchReferenceUpdate, StackActions, TargetUpdate};
use itertools::Itertools;
use tempfile::TempDir;
@ -788,7 +788,7 @@ fn test_ctx(ctx: &CommandContext) -> Result<TestContext> {
})
}
struct TestContext<'a> {
branch: gitbutler_stack::Branch,
branch: gitbutler_stack::Stack,
/// Oldest commit first
commits: Vec<git2::Commit<'a>>,
/// Oldest commit first

View File

@ -1,11 +1,11 @@
mod branch;
mod file_ownership;
mod ownership;
mod stack;
mod state;
mod target;
pub use branch::{Branch, BranchId};
pub use file_ownership::OwnershipClaim;
pub use ownership::{reconcile_claims, BranchOwnershipClaims, ClaimOutcome};
pub use stack::{Stack, StackId};
pub use state::{VirtualBranches as VirtualBranchesState, VirtualBranchesHandle};
pub use target::Target;

View File

@ -4,7 +4,7 @@ use anyhow::Result;
use itertools::Itertools;
use serde::{Deserialize, Serialize, Serializer};
use crate::{file_ownership::OwnershipClaim, Branch};
use crate::{file_ownership::OwnershipClaim, Stack};
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct BranchOwnershipClaims {
@ -93,12 +93,12 @@ impl BranchOwnershipClaims {
#[derive(Debug, Clone)]
pub struct ClaimOutcome {
pub updated_branch: Branch,
pub updated_branch: Stack,
pub removed_claims: Vec<OwnershipClaim>,
}
pub fn reconcile_claims(
all_branches: Vec<Branch>,
claiming_branch: &Branch,
all_branches: Vec<Stack>,
claiming_branch: &Stack,
new_claims: &[OwnershipClaim],
) -> Result<Vec<ClaimOutcome>> {
let mut other_branches = all_branches

View File

@ -6,15 +6,15 @@ use serde::{Deserialize, Serialize};
use crate::ownership::BranchOwnershipClaims;
pub type BranchId = Id<Branch>;
pub type StackId = Id<Stack>;
// this is the struct for the virtual branch data that is stored in our data
// store. it is more or less equivalent to a git branch reference, but it is not
// stored or accessible from the git repository itself. it is stored in our
// session storage under the branches/ directory.
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct Branch {
pub id: BranchId,
pub struct Stack {
pub id: StackId,
/// A user-specified name with no restrictions.
/// It will be normalized except to be a valid [ref-name](Branch::refname()) if named `refs/gitbutler/<normalize(name)>`.
pub name: String,
@ -83,7 +83,7 @@ where
Ok(x)
}
impl Branch {
impl Stack {
/// Creates a new `Branch` with the given name. The `in_workspace` flag is set to `true`.
#[allow(clippy::too_many_arguments)]
pub fn new(
@ -99,7 +99,7 @@ impl Branch {
) -> Self {
let now = gitbutler_time::time::now_ms();
Self {
id: BranchId::generate(),
id: StackId::generate(),
name,
notes: String::new(),
source_refname,
@ -132,10 +132,10 @@ impl Branch {
}
}
impl TryFrom<&Branch> for VirtualRefname {
impl TryFrom<&Stack> for VirtualRefname {
type Error = anyhow::Error;
fn try_from(value: &Branch) -> std::result::Result<Self, Self::Error> {
fn try_from(value: &Stack) -> std::result::Result<Self, Self::Error> {
Ok(Self {
branch: normalize_branch_name(&value.name)?,
})

View File

@ -12,7 +12,7 @@ use itertools::Itertools;
use serde::{Deserialize, Serialize};
use crate::{
branch::{Branch, BranchId},
stack::{Stack, StackId},
target::Target,
};
@ -22,24 +22,24 @@ pub struct VirtualBranches {
/// This is the target/base that is set when a repo is added to gb
default_target: Option<Target>,
/// The targets for each virtual branch
branch_targets: HashMap<BranchId, Target>,
branch_targets: HashMap<StackId, Target>,
/// The current state of the virtual branches
branches: HashMap<BranchId, Branch>,
branches: HashMap<StackId, Stack>,
}
impl VirtualBranches {
/// Lists all virtual branches that are in the user's workspace.
///
/// Errors if the file cannot be read or written.
pub(crate) fn list_all_branches(&self) -> Result<Vec<Branch>> {
let branches: Vec<Branch> = self.branches.values().cloned().collect();
pub(crate) fn list_all_branches(&self) -> Result<Vec<Stack>> {
let branches: Vec<Stack> = self.branches.values().cloned().collect();
Ok(branches)
}
/// Lists all virtual branches that are in the user's workspace.
///
/// Errors if the file cannot be read or written.
pub fn list_branches_in_workspace(&self) -> Result<Vec<Branch>> {
pub fn list_branches_in_workspace(&self) -> Result<Vec<Stack>> {
self.list_all_branches().map(|branches| {
branches
.into_iter()
@ -97,7 +97,7 @@ impl VirtualBranchesHandle {
/// Sets the state of the given virtual branch.
///
/// Errors if the file cannot be read or written.
pub fn set_branch(&self, branch: Branch) -> Result<()> {
pub fn set_branch(&self, branch: Stack) -> Result<()> {
let mut virtual_branches = self.read_file()?;
virtual_branches.branches.insert(branch.id, branch);
self.write_file(&virtual_branches)?;
@ -107,7 +107,7 @@ impl VirtualBranchesHandle {
/// Marks a particular branch as not in the workspace
///
/// Errors if the file cannot be read or written.
pub fn mark_as_not_in_workspace(&self, id: BranchId) -> Result<()> {
pub fn mark_as_not_in_workspace(&self, id: StackId) -> Result<()> {
let mut branch = self.get_branch(id)?;
branch.in_workspace = false;
self.set_branch(branch)?;
@ -117,7 +117,7 @@ impl VirtualBranchesHandle {
pub fn find_by_source_refname_where_not_in_workspace(
&self,
refname: &Refname,
) -> Result<Option<Branch>> {
) -> Result<Option<Stack>> {
let branches = self.list_all_branches()?;
Ok(branches.into_iter().find(|branch| {
if branch.in_workspace {
@ -135,7 +135,7 @@ impl VirtualBranchesHandle {
/// Gets the state of the given virtual branch.
///
/// Errors if the file cannot be read or written.
pub fn get_branch_in_workspace(&self, id: BranchId) -> Result<Branch> {
pub fn get_branch_in_workspace(&self, id: StackId) -> Result<Stack> {
self.try_branch_in_workspace(id)?
.ok_or_else(|| anyhow!("branch with ID {id} not found"))
}
@ -143,20 +143,20 @@ impl VirtualBranchesHandle {
/// Gets the state of the given virtual branch.
///
/// Errors if the file cannot be read or written.
pub fn get_branch(&self, id: BranchId) -> Result<Branch> {
pub fn get_branch(&self, id: StackId) -> Result<Stack> {
self.try_branch(id)?
.ok_or_else(|| anyhow!("branch with ID {id} not found"))
}
/// 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>> {
pub fn try_branch_in_workspace(&self, id: StackId) -> Result<Option<Stack>> {
Ok(self.try_branch(id)?.filter(|branch| branch.in_workspace))
}
/// Gets the state of the given virtual branch returning `Some(branch)` or `None`
/// if that branch doesn't exist.
pub fn try_branch(&self, id: BranchId) -> Result<Option<Branch>> {
pub fn try_branch(&self, id: StackId) -> Result<Option<Stack>> {
let virtual_branches = self.read_file()?;
Ok(virtual_branches.branches.get(&id).cloned())
}
@ -164,16 +164,16 @@ impl VirtualBranchesHandle {
/// Lists all branches in `virtual_branches.toml`.
///
/// Errors if the file cannot be read or written.
pub fn list_all_branches(&self) -> Result<Vec<Branch>> {
pub fn list_all_branches(&self) -> Result<Vec<Stack>> {
let virtual_branches = self.read_file()?;
let branches: Vec<Branch> = virtual_branches.branches.values().cloned().collect();
let branches: Vec<Stack> = virtual_branches.branches.values().cloned().collect();
Ok(branches)
}
/// Lists all virtual branches that are in the user's workspace.
///
/// Errors if the file cannot be read or written.
pub fn list_branches_in_workspace(&self) -> Result<Vec<Branch>> {
pub fn list_branches_in_workspace(&self) -> Result<Vec<Stack>> {
self.list_all_branches().map(|branches| {
branches
.into_iter()
@ -218,14 +218,14 @@ impl VirtualBranchesHandle {
.list_branches_in_workspace()?
.iter()
.sorted_by_key(|branch| branch.order)
.collect::<Vec<&Branch>>()
.collect::<Vec<&Stack>>()
.last()
.map_or(0, |b| b.order + 1);
Ok(order)
}
pub fn delete_branch_entry(&self, branch_id: &BranchId) -> Result<()> {
pub fn delete_branch_entry(&self, branch_id: &StackId) -> Result<()> {
let mut virtual_branches = self.read_file()?;
virtual_branches.branches.remove(branch_id);
self.write_file(&virtual_branches)?;

View File

@ -1,11 +1,11 @@
use std::{path::PathBuf, vec};
use gitbutler_diff::Hunk;
use gitbutler_stack::{reconcile_claims, Branch, BranchOwnershipClaims, OwnershipClaim};
use gitbutler_stack::{reconcile_claims, BranchOwnershipClaims, OwnershipClaim, Stack};
#[test]
fn reconcile_ownership_simple() {
let mut branch_a = Branch::new(
let mut branch_a = Stack::new(
"a".to_string(),
None,
None,
@ -36,7 +36,7 @@ fn reconcile_ownership_simple() {
branch_a.created_timestamp_ms = u128::default();
branch_a.updated_timestamp_ms = u128::default();
let mut branch_b = Branch::new(
let mut branch_b = Stack::new(
"b".to_string(),
None,
None,
@ -60,7 +60,7 @@ fn reconcile_ownership_simple() {
branch_b.created_timestamp_ms = u128::default();
branch_b.updated_timestamp_ms = u128::default();
let all_branches: Vec<Branch> = vec![branch_a.clone(), branch_b.clone()];
let all_branches: Vec<Stack> = vec![branch_a.clone(), branch_b.clone()];
let claim: Vec<OwnershipClaim> = vec![OwnershipClaim {
file_path: PathBuf::from("foo"),
hunks: vec![

View File

@ -7,7 +7,7 @@ use gitbutler_project as projects;
use gitbutler_project::ProjectId;
use gitbutler_reference::RemoteRefname;
use gitbutler_repo::{RepoActionsExt, RepositoryExt};
use gitbutler_stack::BranchId;
use gitbutler_stack::StackId;
#[derive(Clone)]
pub struct App {
@ -45,7 +45,7 @@ impl App {
project_id: ProjectId,
remote_name: &str,
branch_name: &str,
askpass: Option<Option<BranchId>>,
askpass: Option<Option<StackId>>,
) -> Result<()> {
let project = self.projects().get(project_id)?;
let ctx = CommandContext::open(&project)?;

View File

@ -1,7 +1,7 @@
use gitbutler_branch_actions::stack::CreateSeriesRequest;
use gitbutler_project as projects;
use gitbutler_project::ProjectId;
use gitbutler_stack::BranchId;
use gitbutler_stack::StackId;
use tauri::State;
use tracing::instrument;
@ -14,7 +14,7 @@ pub fn create_series(
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
request: CreateSeriesRequest,
) -> Result<(), Error> {
let project = projects.get(project_id)?;
@ -29,7 +29,7 @@ pub fn remove_series(
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
head_name: String,
) -> Result<(), Error> {
let project = projects.get(project_id)?;
@ -44,7 +44,7 @@ pub fn update_series_name(
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
head_name: String,
new_head_name: String,
) -> Result<(), Error> {
@ -65,7 +65,7 @@ pub fn update_series_description(
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
head_name: String,
description: Option<String>,
) -> Result<(), Error> {
@ -86,7 +86,7 @@ pub fn push_stack(
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
with_force: bool,
) -> Result<(), Error> {
let project = projects.get(project_id)?;

View File

@ -15,7 +15,7 @@ pub mod commands {
use gitbutler_reference::{
normalize_branch_name as normalize_name, ReferenceName, Refname, RemoteRefname,
};
use gitbutler_stack::{BranchId, BranchOwnershipClaims};
use gitbutler_stack::{BranchOwnershipClaims, StackId};
use std::path::PathBuf;
use tauri::State;
use tracing::instrument;
@ -34,7 +34,7 @@ pub mod commands {
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch: BranchId,
branch: StackId,
message: &str,
ownership: Option<BranchOwnershipClaims>,
run_hooks: bool,
@ -73,7 +73,7 @@ pub mod commands {
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch: BranchCreateRequest,
) -> Result<BranchId, Error> {
) -> Result<StackId, Error> {
let project = projects.get(project_id)?;
let branch_id = gitbutler_branch_actions::create_virtual_branch(&project, &branch)?;
emit_vbranches(&windows, project_id);
@ -103,7 +103,7 @@ pub mod commands {
project_id: ProjectId,
branch: Refname,
remote: Option<RemoteRefname>,
) -> Result<BranchId, Error> {
) -> Result<StackId, Error> {
let project = projects.get(project_id)?;
let branch_id =
gitbutler_branch_actions::create_virtual_branch_from_branch(&project, &branch, remote)?;
@ -117,7 +117,7 @@ pub mod commands {
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch: BranchId,
branch: StackId,
) -> Result<(), Error> {
let project = projects.get(project_id)?;
gitbutler_branch_actions::integrate_upstream_commits(&project, branch)?;
@ -224,7 +224,7 @@ pub mod commands {
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
) -> Result<(), Error> {
let project = projects.get(project_id)?;
gitbutler_branch_actions::unapply_without_saving_virtual_branch(&project, branch_id)?;
@ -238,7 +238,7 @@ pub mod commands {
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch: BranchId,
branch: StackId,
) -> Result<(), Error> {
let project = projects.get(project_id)?;
gitbutler_branch_actions::save_and_unapply_virutal_branch(&project, branch)?;
@ -266,7 +266,7 @@ pub mod commands {
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
files: Vec<PathBuf>,
) -> Result<(), Error> {
let project = projects.get(project_id)?;
@ -281,7 +281,7 @@ pub mod commands {
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
with_force: bool,
) -> Result<PushResult, Error> {
let project = projects.get(project_id)?;
@ -326,7 +326,7 @@ pub mod commands {
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
target_commit_oid: String,
) -> Result<(), Error> {
let project = projects.get(project_id)?;
@ -342,7 +342,7 @@ pub mod commands {
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
commit_oid: String,
ownership: BranchOwnershipClaims,
) -> Result<String, Error> {
@ -359,7 +359,7 @@ pub mod commands {
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
from_commit_oid: String,
to_commit_oid: String,
ownership: BranchOwnershipClaims,
@ -384,7 +384,7 @@ pub mod commands {
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
commit_oid: String,
) -> Result<(), Error> {
let project = projects.get(project_id)?;
@ -400,7 +400,7 @@ pub mod commands {
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
commit_oid: String,
offset: i32,
) -> Result<(), Error> {
@ -417,7 +417,7 @@ pub mod commands {
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
commit_oid: String,
offset: i32,
) -> Result<(), Error> {
@ -481,7 +481,7 @@ pub mod commands {
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
target_commit_oid: String,
) -> Result<(), Error> {
let project = projects.get(project_id)?;
@ -531,7 +531,7 @@ pub mod commands {
projects: State<'_, projects::Controller>,
project_id: ProjectId,
commit_oid: String,
target_branch_id: BranchId,
target_branch_id: StackId,
) -> Result<(), Error> {
let project = projects.get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
@ -546,7 +546,7 @@ pub mod commands {
windows: State<'_, WindowState>,
projects: State<'_, projects::Controller>,
project_id: ProjectId,
branch_id: BranchId,
branch_id: StackId,
commit_oid: String,
message: &str,
) -> Result<(), Error> {