1
1
use crate :: WorkspaceCommit ;
2
- use bstr:: ByteSlice ;
2
+ use crate :: ui:: StackEntryNoOpt ;
3
+ use bstr:: { BString , ByteSlice } ;
4
+
5
+ /// A minimal stack for use by [WorkspaceCommit::new_from_stacks()].
6
+ pub struct Stack {
7
+ /// The tip of the top-most branch, i.e., the most recent commit that would become the parent of new commits of the topmost stack branch.
8
+ pub tip : gix:: ObjectId ,
9
+ /// The short name of the stack, which is the name of the top-most branch, like `main` or `feature/branch` or `origin/tracking-some-PR`
10
+ /// or something entirely made up.
11
+ pub name : Option < BString > ,
12
+ }
13
+
14
+ impl From < StackEntryNoOpt > for Stack {
15
+ fn from ( value : StackEntryNoOpt ) -> Self {
16
+ Stack {
17
+ tip : value. tip ,
18
+ name : value. name ( ) . map ( ToOwned :: to_owned) ,
19
+ }
20
+ }
21
+ }
3
22
4
23
/// Construction
5
24
impl < ' repo > WorkspaceCommit < ' repo > {
@@ -20,10 +39,11 @@ impl<'repo> WorkspaceCommit<'repo> {
20
39
/// It still needs its tree set to something non-empty.
21
40
///
22
41
/// `object_hash` is needed to create an empty tree hash.
23
- pub ( crate ) fn create_commit_from_vb_state (
24
- stacks : & [ crate :: ui :: StackEntryNoOpt ] ,
42
+ pub ( crate ) fn new_from_stacks (
43
+ stacks : impl IntoIterator < Item = impl Into < Stack > > ,
25
44
object_hash : gix:: hash:: Kind ,
26
45
) -> gix:: objs:: Commit {
46
+ let stacks = stacks. into_iter ( ) . map ( Into :: into) . collect :: < Vec < _ > > ( ) ;
27
47
// message that says how to get back to where they were
28
48
let mut message = Self :: GITBUTLER_WORKSPACE_COMMIT_TITLE . to_string ( ) ;
29
49
message. push_str ( "\n \n " ) ;
@@ -44,8 +64,8 @@ impl<'repo> WorkspaceCommit<'repo> {
44
64
message. push_str ( "If you commit on this branch, GitButler will throw it away.\n \n " ) ;
45
65
if !stacks. is_empty ( ) {
46
66
message. push_str ( "Here are the branches that are currently applied:\n " ) ;
47
- for branch in stacks {
48
- if let Some ( name) = branch. name ( ) {
67
+ for branch in & stacks {
68
+ if let Some ( name) = & branch. name {
49
69
message. push_str ( " - " ) ;
50
70
message. push_str ( name. to_str_lossy ( ) . as_ref ( ) ) ;
51
71
message. push ( '\n' ) ;
0 commit comments