1
- use crate :: commit_engine:: { Destination , MoveSourceCommit , RejectionReason , apply_hunks} ;
1
+ use crate :: commit_engine:: { MoveSourceCommit , RejectionReason , apply_hunks} ;
2
2
use crate :: { DiffSpec , HunkHeader } ;
3
3
use bstr:: { BStr , ByteSlice } ;
4
4
use but_core:: { RepositoryExt , UnifiedDiff } ;
@@ -17,8 +17,8 @@ pub struct CreateTreeOutcome {
17
17
/// when merging the workspace commit, or because the specified hunks didn't match exactly due to changes
18
18
/// that happened in the meantime, or if a file without a change was specified.
19
19
pub rejected_specs : Vec < ( RejectionReason , DiffSpec ) > ,
20
- /// The newly created seen from tree that acts as the destination of the changes, or `None` if no commit could be
21
- /// created as all changes-requests were rejected.
20
+ /// The newly created seen from tree that acts as the destination of the changes, or `None` if no tree could be
21
+ /// created as all changes-requests were rejected (or there was no change) .
22
22
pub destination_tree : Option < gix:: ObjectId > ,
23
23
/// If `destination_tree` is `Some(_)`, this field is `Some(_)` as well and denotes the base-tree + all changes.
24
24
/// If the applied changes were from the worktree, it's `HEAD^{tree}` + changes.
@@ -29,28 +29,11 @@ pub struct CreateTreeOutcome {
29
29
/// Like [`create_commit()`], but lower-level and only returns a new tree, without finally associating it with a commit.
30
30
pub fn create_tree (
31
31
repo : & gix:: Repository ,
32
- destination : & Destination ,
32
+ target_tree : gix :: ObjectId ,
33
33
move_source : Option < MoveSourceCommit > ,
34
34
changes : Vec < DiffSpec > ,
35
35
context_lines : u32 ,
36
36
) -> anyhow:: Result < CreateTreeOutcome > {
37
- let target_tree = match destination {
38
- Destination :: NewCommit {
39
- parent_commit_id : None ,
40
- ..
41
- } => gix:: ObjectId :: empty_tree ( repo. object_hash ( ) ) ,
42
- Destination :: NewCommit {
43
- parent_commit_id : Some ( base_commit) ,
44
- ..
45
- }
46
- | Destination :: AmendCommit {
47
- commit_id : base_commit,
48
- ..
49
- } => but_core:: Commit :: from_id ( base_commit. attach ( repo) ) ?
50
- . tree_id_or_auto_resolution ( ) ?
51
- . detach ( ) ,
52
- } ;
53
-
54
37
let mut changes: Vec < _ > = changes. into_iter ( ) . map ( Ok ) . collect ( ) ;
55
38
let ( new_tree, changed_tree_pre_cherry_pick) = if changes. is_empty ( ) {
56
39
( Some ( target_tree) , None )
@@ -81,7 +64,7 @@ pub fn create_tree(
81
64
let tree_with_changes = if new_tree == actual_base_tree
82
65
&& changes. iter ( ) . all ( |c| {
83
66
c. is_ok ( )
84
- // Some rejections are OK and we want to create a commit anyway.
67
+ // Some rejections are OK, and we want to create a commit anyway.
85
68
|| !matches ! (
86
69
c,
87
70
Err ( ( RejectionReason :: CherryPickMergeConflict , _) )
0 commit comments