1
1
//! The ability to create a Git representation of diverse 'state' that can be restored at a later time.
2
2
3
- ///
4
- pub mod create_tree {
5
- use bstr:: BString ;
6
-
7
- /// A way to determine what should be included in the snapshot when calling [create_tree()](function::create_tree).
8
- pub struct State < ' a > {
9
- /// The result of a previous worktree changes call.
10
- ///
11
- /// It contains detailed information about the complete set of possible changes to become part of the worktree.
12
- pub changes : & ' a but_core:: WorktreeChanges ,
13
- /// Repository-relative and slash-separated paths that match any change in the [`changes`](State::changes) field.
14
- /// **It's an error if there is no match.** as there is not supposed to be a snapshot without a change to the working tree.
15
- pub selection : Vec < BString > ,
16
- /// If `true`, store the current `HEAD` reference, i.e. its target, as well as the targets of all refs it's pointing to by symbolic link.
17
- pub head : bool ,
18
- }
19
-
20
- /// Contains all state that the snapshot contains.
21
- #[ derive( Debug , Copy , Clone ) ]
22
- pub struct Outcome {
23
- /// The snapshot itself, with all the subtrees available that are also listed in this structure.
24
- pub snapshot_tree : gix:: ObjectId ,
25
- /// For good measure, the input `HEAD^{tree}` that is used as the basis to learn about worktree changes.
26
- pub head_tree : gix:: ObjectId ,
27
- /// The `head_tree` with the selected worktree changes applied, suitable for being stored in a commit.
28
- pub wortree : gix:: ObjectId ,
29
- /// The tree representing the current changed index, without conflicts, or `None` if there was no change to the index.
30
- pub index : Option < gix:: ObjectId > ,
31
- /// A tree with files in a custom storage format to allow keeping conflicting blobs reachable, along with detailed conflict information
32
- /// to allow restoring the conflict entries in the index.
33
- pub index_conflicts : Option < gix:: ObjectId > ,
34
- /// The tree representing the reference targets of all references within the *workspace*.
35
- pub workspace_references : Option < gix:: ObjectId > ,
36
- /// The tree representing the reference targets of all references reachable from `HEAD`, so typically `HEAD` itself, and the
37
- /// target object of the reference it is pointing to.
38
- pub head_references : Option < gix:: ObjectId > ,
39
- /// The tree representing the metadata of all references within the *workspace*.
40
- pub metadata : Option < gix:: ObjectId > ,
41
- }
42
-
43
- pub ( super ) mod function {
44
- use super :: { Outcome , State } ;
45
- use but_core:: RefMetadata ;
46
- /// Create a tree that represents the snapshot for the given `selection`, with the basis for everything
47
- /// being the `head_tree_id` (i.e. the tree to which `HEAD` is ultimately pointing to).
48
- ///
49
- /// If `workspace_and_meta` is not `None`, the workspace and metadata to store in the snapshot.
50
- /// We will only store reference positions, and assume that their commits are safely stored in the reflog to not
51
- /// be garbage collected. Metadata is only stored for the references that are included in the `workspace`.
52
- ///
53
- /// Note that objects will be written into the repository behind `head_tree_id` unless it's configured
54
- /// to keep everything in memory.
55
- pub fn create_tree (
56
- _head_tree_id : gix:: Id < ' _ > ,
57
- _selection : State ,
58
- _workspace_and_meta : Option < ( & but_graph:: projection:: Workspace , & impl RefMetadata ) > ,
59
- ) -> anyhow:: Result < Outcome > {
60
- todo ! ( )
61
- }
62
- }
63
- }
3
+ /// Structures to call the [create_tree()] function.
4
+ pub mod create_tree;
64
5
pub use create_tree:: function:: create_tree;
65
6
66
7
/// Utilities related to resolving previously created snapshots.
@@ -70,9 +11,12 @@ pub mod resolve_tree {
70
11
pub struct Outcome < ' repo > {
71
12
/// The cherry-pick result as merge between the target worktree and the snapshot, **possibly with conflicts**.
72
13
///
73
- /// This tree, may be checked out to the working tree, with or without conflicts.
74
- pub workspace_cherry_pick : gix:: merge:: tree:: Outcome < ' repo > ,
14
+ /// This tree, may be checked out to the working tree, with or without conflicts - it's entirely left to the caller.
15
+ /// It's `None` if the was no worktree change.
16
+ pub workspace_cherry_pick : Option < gix:: merge:: tree:: Outcome < ' repo > > ,
75
17
/// If an index was stored in the snapshot, this is the reconstructed index, including conflicts.
18
+ ///
19
+ /// It's `None` if there were no index-only changes.
76
20
pub index : Option < gix:: index:: State > ,
77
21
/// Reference edits that when applied in a transaction will set the workspace back to where it was. Only available
78
22
/// if it was part of the snapshot to begin with.
@@ -89,22 +33,33 @@ pub mod resolve_tree {
89
33
pub branches : Vec < ( gix:: refs:: FullName , but_core:: ref_metadata:: Branch ) > ,
90
34
}
91
35
92
- pub ( super ) mod function {
93
- use super :: Outcome ;
36
+ /// Options for use in [super::resolve_tree()].
37
+ #[ derive( Debug , Clone ) ]
38
+ pub struct Options {
39
+ /// If set, the non-default options to use when cherry-picking the worktree changes onto the target tree.
40
+ ///
41
+ /// If `None`, perform the merge just like Git.
42
+ pub workspace_cherry_pick : Option < gix:: merge:: tree:: Options > ,
43
+ }
94
44
45
+ pub ( super ) mod function {
46
+ use super :: { Options , Outcome } ;
95
47
/// Given the `snapshot_tree` as previously returned via [super::create_tree::Outcome::snapshot_tree], extract data and…
96
48
///
97
49
/// * …cherry-pick the worktree changes onto the `target_worktree_tree_id`, which is assumed to represent the future working directory state
98
- /// and which either contains the worktree changes or *preferably* is the `HEAD^{tree}` as the working directory is clean.
50
+ /// and which either contains the worktree changes or *preferably* is the `HEAD^{tree}` as the working directory is clean.
99
51
/// * …reconstruct the index to write into `.git/index`, assuming that the current `.git/index` is clean.
100
52
/// * …produce reference edits to put the workspace refs back into place with.
101
53
/// * …produce metadata that if set will represent the metadata of the entire workspace.
102
54
///
103
55
/// Note that none of this data is actually manifested in the repository or working tree, they only exists as objects in the Git database,
104
56
/// assuming in-memory objects aren't used in the repository.
105
- pub fn resolve_tree < ' repo > (
57
+ pub fn resolve_tree (
106
58
_snapshot_tree : gix:: Id < ' _ > ,
107
59
_target_worktree_tree_id : gix:: ObjectId ,
60
+ Options {
61
+ workspace_cherry_pick : _,
62
+ } : Options ,
108
63
) -> anyhow:: Result < Outcome < ' _ > > {
109
64
todo ! ( )
110
65
}
@@ -152,13 +107,13 @@ mod commit {
152
107
type Err = anyhow:: Error ;
153
108
154
109
fn from_str ( s : & str ) -> anyhow:: Result < Self , Self :: Err > {
155
- let parts: Vec < & str > = s. splitn ( 2 , ':' ) . collect ( ) ;
156
- if parts. len ( ) != 2 {
110
+ let mut parts = s. splitn ( 2 , ':' ) ;
111
+ let ( Some ( key ) , Some ( value ) ) = ( parts. next ( ) , parts . next ( ) ) else {
157
112
return Err ( anyhow ! ( "Invalid trailer format, expected `key: value`" ) ) ;
158
- }
159
- let unescaped_value = parts [ 1 ] . trim ( ) . replace ( "\\ n" , "\n " ) ;
113
+ } ;
114
+ let unescaped_value = value . trim ( ) . replace ( "\\ n" , "\n " ) ;
160
115
Ok ( Self {
161
- key : parts [ 0 ] . trim ( ) . to_string ( ) ,
116
+ key : key . trim ( ) . to_string ( ) ,
162
117
value : unescaped_value,
163
118
} )
164
119
}
0 commit comments