|
131 | 131 | //! For instance, if a references is `refs/heads/gitbutler/workspace/one`, then the stash reference is in
|
132 | 132 | //! `<namespace: gitbutler-stashes>/refs/heads/gitbutler/workspace/one`. The reason for this is that they will not
|
133 | 133 | //! be garbage-collected that way.
|
134 |
| -//! Note that any ref, like `refs/heads/feature` can carry a stash, so *workspace references* aren't special. |
| 134 | +//! Note that any ref, like `refs/heads/gitbutler/workspace` can carry one or more stashes, so *workspace references* aren't special. |
135 | 135 | //!
|
136 | 136 | //! *This also makes stashes enumerable*. It's notable that it's entirely possible for stashes to become *orphaned*,
|
137 | 137 | //! i.e. their workspace commit (that the stash commit sits on top of) doesn't have a reference *with the same name*
|
@@ -530,7 +530,55 @@ impl Stack {
|
530 | 530 | }
|
531 | 531 | }
|
532 | 532 |
|
533 |
| -/// Return all stack segments within the given `stack`. |
534 |
| -pub fn stack_segments(stack: Stack) -> anyhow::Result<Vec<ref_info::ui::Segment>> { |
| 533 | +mod create_reference { |
| 534 | + /// For use in [`ReferenceAnchor`]. |
| 535 | + #[derive(Debug, Clone, Copy)] |
| 536 | + pub enum ReferencePosition { |
| 537 | + /// The new dependent branch will appear above its anchor. |
| 538 | + Above, |
| 539 | + /// The new dependent branch will appear below its anchor. |
| 540 | + Below, |
| 541 | + } |
| 542 | + |
| 543 | + /// For use in [`create_reference()`]. |
| 544 | + #[derive(Debug, Clone)] |
| 545 | + pub enum ReferenceAnchor { |
| 546 | + /// Create the reference above this commit. |
| 547 | + /// This will fail if there already is a named segment |
| 548 | + /// at exactly this commit. |
| 549 | + AtCommit { |
| 550 | + /// The commit that `position` relates to. |
| 551 | + commit: gix::ObjectId, |
| 552 | + /// The reference points at `commit` when [`ReferencePosition::Above`], |
| 553 | + /// or the first parent of `commit` when [`ReferencePosition::Below`]. |
| 554 | + position: ReferencePosition, |
| 555 | + }, |
| 556 | + /// Create a dependent reference in relation to the commit pointed to by another reference. |
| 557 | + AtReference { |
| 558 | + /// The reference that `position` relates to. |
| 559 | + ref_name: gix::refs::FullName, |
| 560 | + /// The reference points at the commit of `ref_name` when [`ReferencePosition::Above`], |
| 561 | + /// or the first parent the first commit of `ref_name` when [`ReferencePosition::Below`]. |
| 562 | + position: ReferencePosition, |
| 563 | + }, |
| 564 | + } |
| 565 | +} |
| 566 | +pub use create_reference::*; |
| 567 | + |
| 568 | +/// Create a new reference named `ref_name` in relation to `anchor`, which is expected to be contained |
| 569 | +/// in any stack in `workspace`, and place it into `repo`. |
| 570 | +/// Fail if the reference already exists *and* points somewhere else. |
| 571 | +/// Note that `workspace` is frozen in time and won't contain the newly created reference or new segment. |
| 572 | +/// `meta` will be created for `ref_name` as well, or its data update if it did exist already. |
| 573 | +/// |
| 574 | +/// - if there is no managed workspace, then dependent branches must be exclusive on each commit to identify ordering |
| 575 | +/// - if there is a workspace, we store the order in workspace metadata |
| 576 | +pub fn create_reference( |
| 577 | + repo: &gix::Repository, |
| 578 | + ref_name: &gix::refs::FullNameRef, |
| 579 | + anchor: ReferenceAnchor, |
| 580 | + workspace: &but_graph::projection::Workspace<'_>, |
| 581 | + meta: &mut impl RefMetadata, |
| 582 | +) -> anyhow::Result<()> { |
535 | 583 | todo!()
|
536 | 584 | }
|
0 commit comments