Skip to main content

Stack

Struct Stack 

Source
pub struct Stack {
    pub branches: Vec<StackBranch>,
    pub merged: Vec<MergedBranch>,
}
Expand description

A stack of dependent branches forming a PR chain.

Fields§

§branches: Vec<StackBranch>

Ordered list of branches from base to tip.

§merged: Vec<MergedBranch>

Branches that have been merged (for preserving history in PR comments).

Implementations§

Source§

impl Stack

Source

pub const fn new() -> Self

Create a new empty stack.

Source

pub fn find_branch(&self, name: &str) -> Option<&StackBranch>

Find a branch by name.

Source

pub fn find_branch_mut(&mut self, name: &str) -> Option<&mut StackBranch>

Find a branch by name (mutable).

Source

pub fn add_branch(&mut self, branch: StackBranch)

Add a new branch to the stack.

Source

pub fn remove_branch(&mut self, name: &str) -> Option<StackBranch>

Remove a branch from the stack.

Source

pub fn mark_merged(&mut self, name: &str) -> Option<StackBranch>

Mark a branch as merged, moving it from active to merged list.

This preserves the branch info for stack comment history, including the original parent for ancestry chain traversal. Returns the removed branch if found.

Source

pub fn find_merged(&self, name: &str) -> Option<&MergedBranch>

Find a merged branch by name.

Source

pub fn find_merged_by_pr(&self, pr: u64) -> Option<&MergedBranch>

Find a merged branch by PR number.

Source

pub fn clear_merged_if_empty(&mut self)

Clear merged branches when stack is empty.

This should be called after merge operations to clean up when the entire stack has been merged.

Source

pub fn children_of(&self, name: &str) -> Vec<&StackBranch>

Get all children of a branch.

Source

pub fn descendants(&self, name: &str) -> Vec<&StackBranch>

Get all descendants of a branch in topological order (parents before children).

This includes children, grandchildren, etc. The branch itself is NOT included.

Source

pub fn ancestry(&self, name: &str) -> Vec<&StackBranch>

Get the ancestry chain for a branch (from root to the branch).

Source

pub const fn is_empty(&self) -> bool

Check if the stack is empty.

Source

pub const fn len(&self) -> usize

Get the number of branches in the stack.

Source

pub fn would_create_cycle(&self, branch: &str, new_parent: &str) -> bool

Check if reparenting branch to new_parent would create a cycle.

A cycle would occur if the new parent is a descendant of the branch (e.g., setting A’s parent to B when B is already a child of A).

Source

pub fn reparent(&mut self, branch: &str, new_parent: Option<&str>) -> Result<()>

Reparent a branch to a new parent.

Updates the parent field of the specified branch. Does not perform any git operations - the caller is responsible for rebasing.

§Errors

Returns an error if the branch is not found or if the reparent would create a cycle.

Trait Implementations§

Source§

impl Clone for Stack

Source§

fn clone(&self) -> Stack

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Stack

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Stack

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Stack

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Stack

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Stack

§

impl RefUnwindSafe for Stack

§

impl Send for Stack

§

impl Sync for Stack

§

impl Unpin for Stack

§

impl UnsafeUnpin for Stack

§

impl UnwindSafe for Stack

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,