1
1
use anyhow:: Context ;
2
2
use std:: borrow:: Cow ;
3
3
4
- /// For use in [`ReferenceAnchor `].
4
+ /// For use in [`Anchor `].
5
5
#[ derive( Debug , Clone , Copy , serde:: Serialize , serde:: Deserialize ) ]
6
- pub enum ReferencePosition {
6
+ pub enum Position {
7
7
/// The new dependent branch will appear above its anchor.
8
8
Above ,
9
9
/// The new dependent branch will appear below its anchor.
@@ -33,7 +33,7 @@ impl<'a> From<&'a but_graph::projection::StackCommit> for MinimalCommit<'a> {
33
33
}
34
34
}
35
35
36
- impl ReferencePosition {
36
+ impl Position {
37
37
fn resolve_commit (
38
38
& self ,
39
39
commit : MinimalCommit < ' _ > ,
@@ -43,15 +43,13 @@ impl ReferencePosition {
43
43
return Ok ( commit. id ) ;
44
44
}
45
45
Ok ( match self {
46
- ReferencePosition :: Above => commit. id ,
47
- ReferencePosition :: Below => {
48
- commit. parent_ids . iter ( ) . cloned ( ) . next ( ) . with_context ( || {
49
- format ! (
50
- "Commit {id} is the first in history and no branch can point below it" ,
51
- id = commit. id
52
- )
53
- } ) ?
54
- }
46
+ Position :: Above => commit. id ,
47
+ Position :: Below => commit. parent_ids . iter ( ) . cloned ( ) . next ( ) . with_context ( || {
48
+ format ! (
49
+ "Commit {id} is the first in history and no branch can point below it" ,
50
+ id = commit. id
51
+ )
52
+ } ) ?,
55
53
} )
56
54
}
57
55
}
@@ -63,7 +61,7 @@ impl ReferencePosition {
63
61
/// go just by commit. We must be specifying it in terms of above/below ref-name when possible,
64
62
/// or else they will always go on top.
65
63
#[ derive( Debug , Clone ) ]
66
- pub enum ReferenceAnchor < ' a > {
64
+ pub enum Anchor < ' a > {
67
65
/// Use a commit as position, which means we always need unambiguous placement
68
66
/// without a way to stack references on top of other references - only on top
69
67
/// of commits their segments may own.
@@ -72,7 +70,7 @@ pub enum ReferenceAnchor<'a> {
72
70
commit_id : gix:: ObjectId ,
73
71
/// `Above` means the reference will point at `commit_id`, `Below` means it points at its
74
72
/// parent if possible.
75
- position : ReferencePosition ,
73
+ position : Position ,
76
74
} ,
77
75
/// Use a segment as reference for positioning the new reference.
78
76
/// Without a workspace, this is the same as saying 'the commit that the segment points to'.
@@ -83,22 +81,22 @@ pub enum ReferenceAnchor<'a> {
83
81
/// if it points to the same commit.
84
82
/// `Below` means the reference will be right below the segment with `ref_name` even
85
83
/// if it points to the same commit.
86
- position : ReferencePosition ,
84
+ position : Position ,
87
85
} ,
88
86
}
89
87
90
- impl < ' a > ReferenceAnchor < ' a > {
88
+ impl < ' a > Anchor < ' a > {
91
89
/// Create a new instance with an object ID as anchor.
92
- pub fn at_id ( commit_id : impl Into < gix:: ObjectId > , position : ReferencePosition ) -> Self {
93
- ReferenceAnchor :: AtCommit {
90
+ pub fn at_id ( commit_id : impl Into < gix:: ObjectId > , position : Position ) -> Self {
91
+ Anchor :: AtCommit {
94
92
commit_id : commit_id. into ( ) ,
95
93
position,
96
94
}
97
95
}
98
96
99
97
/// Create a new instance with a segment name as anchor.
100
- pub fn at_segment ( ref_name : & ' a gix:: refs:: FullNameRef , position : ReferencePosition ) -> Self {
101
- ReferenceAnchor :: AtSegment {
98
+ pub fn at_segment ( ref_name : & ' a gix:: refs:: FullNameRef , position : Position ) -> Self {
99
+ Anchor :: AtSegment {
102
100
ref_name : Cow :: Borrowed ( ref_name) ,
103
101
position,
104
102
}
@@ -108,7 +106,7 @@ impl<'a> ReferenceAnchor<'a> {
108
106
pub ( super ) mod function {
109
107
#![ expect( clippy:: indexing_slicing) ]
110
108
111
- use crate :: branch:: { ReferenceAnchor , ReferencePosition } ;
109
+ use crate :: branch:: create_reference :: { Anchor , Position } ;
112
110
use anyhow:: { Context , bail} ;
113
111
use but_core:: ref_metadata:: { StackId , WorkspaceStack , WorkspaceStackBranch } ;
114
112
use but_core:: { RefMetadata , ref_metadata} ;
@@ -130,7 +128,7 @@ pub(super) mod function {
130
128
/// Return a regenerated Graph that contains the new reference, and from which a new workspace can be derived.
131
129
pub fn create_reference < ' name , T : RefMetadata > (
132
130
ref_name : impl Borrow < gix:: refs:: FullNameRef > ,
133
- anchor : impl Into < Option < ReferenceAnchor < ' name > > > ,
131
+ anchor : impl Into < Option < Anchor < ' name > > > ,
134
132
repo : & gix:: Repository ,
135
133
workspace : & but_graph:: projection:: Workspace < ' _ > ,
136
134
meta : & mut T ,
@@ -172,7 +170,7 @@ pub(super) mod function {
172
170
Some ( Instruction :: Independent ) ,
173
171
)
174
172
}
175
- Some ( ReferenceAnchor :: AtCommit {
173
+ Some ( Anchor :: AtCommit {
176
174
commit_id,
177
175
position,
178
176
} ) => {
@@ -193,7 +191,7 @@ pub(super) mod function {
193
191
194
192
( validate_id, ref_target_id, instruction)
195
193
}
196
- Some ( ReferenceAnchor :: AtSegment { ref_name, position } ) => {
194
+ Some ( Anchor :: AtSegment { ref_name, position } ) => {
197
195
let mut validate_id = true ;
198
196
let ref_target_id = if workspace. has_metadata ( ) {
199
197
let ( stack_idx, seg_idx) = workspace
@@ -373,8 +371,8 @@ pub(super) mod function {
373
371
let branches = & mut ws_meta. stacks [ stack_idx] . branches ;
374
372
branches. insert (
375
373
match position {
376
- ReferencePosition :: Above => branch_idx,
377
- ReferencePosition :: Below => branch_idx + 1 ,
374
+ Position :: Above => branch_idx,
375
+ Position :: Below => branch_idx + 1 ,
378
376
} ,
379
377
WorkspaceStackBranch {
380
378
ref_name : new_ref. to_owned ( ) ,
@@ -394,7 +392,7 @@ pub(super) mod function {
394
392
ws : & but_graph:: projection:: Workspace < ' _ > ,
395
393
anchor_id : gix:: ObjectId ,
396
394
) -> anyhow:: Result < Instruction < ' static > > {
397
- use ReferencePosition :: * ;
395
+ use Position :: * ;
398
396
let ( anchor_stack_idx, anchor_seg_idx, _anchor_commit_idx) = ws
399
397
. find_owner_indexes_by_commit_id ( anchor_id)
400
398
. with_context ( || {
@@ -444,7 +442,7 @@ pub(super) mod function {
444
442
DependentInStack ( StackId ) ,
445
443
Dependent {
446
444
ref_name : Cow < ' a , gix:: refs:: FullNameRef > ,
447
- position : ReferencePosition ,
445
+ position : Position ,
448
446
} ,
449
447
}
450
448
}
0 commit comments