11use crate :: config:: cache:: util:: ApplyLeniencyDefault ;
22use crate :: config:: tree;
3- use crate :: repository:: { blob_merge_options, merge_resource_cache, merge_trees, tree_merge_options} ;
3+ use crate :: prelude:: ObjectIdExt ;
4+ use crate :: repository:: { blob_merge_options, merge_commits, merge_resource_cache, merge_trees, tree_merge_options} ;
45use crate :: Repository ;
56use gix_merge:: blob:: builtin_driver:: text;
67use gix_object:: Write ;
@@ -102,7 +103,7 @@ impl Repository {
102103 }
103104
104105 /// Merge `our_tree` and `their_tree` together, assuming they have the same `ancestor_tree`, to yield a new tree
105- /// which is provided as [tree editor](gix_object ::tree::Editor) to inspect and finalize results at will.
106+ /// which is provided as [tree editor](crate::object ::tree::Editor) to inspect and finalize results at will.
106107 /// No change to the worktree or index is made, but objects may be written to the object database as merge results
107108 /// are stored.
108109 /// If these changes should not be observable outside of this instance, consider [enabling object memory](Self::with_object_memory).
@@ -115,7 +116,7 @@ impl Repository {
115116 ///
116117 /// ### Performance
117118 ///
118- /// It's highly recommended to [set an object cache](crate:: Repository::compute_object_cache_size_for_tree_diffs)
119+ /// It's highly recommended to [set an object cache](Repository::compute_object_cache_size_for_tree_diffs)
119120 /// to avoid extracting the same object multiple times.
120121 pub fn merge_trees (
121122 & self ,
@@ -155,4 +156,71 @@ impl Repository {
155156 failed_on_first_unresolved_conflict,
156157 } )
157158 }
159+
160+ /// Merge `our_commit` and `their_commit` together to yield a new tree which is provided as [tree editor](crate::object::tree::Editor)
161+ /// to inspect and finalize results at will. The merge-base will be determined automatically between both commits, along with special
162+ /// handling in case there are multiple merge-bases.
163+ /// No change to the worktree or index is made, but objects may be written to the object database as merge results
164+ /// are stored.
165+ /// If these changes should not be observable outside of this instance, consider [enabling object memory](Self::with_object_memory).
166+ ///
167+ /// `labels` are typically chosen to identify the refs or names for `our_commit` and `their_commit`, with the ancestor being set
168+ /// automatically as part of the merge-base handling.
169+ ///
170+ /// `options` should be initialized with [`Repository::tree_merge_options().into()`](Self::tree_merge_options()).
171+ ///
172+ /// ### Performance
173+ ///
174+ /// It's highly recommended to [set an object cache](Repository::compute_object_cache_size_for_tree_diffs)
175+ /// to avoid extracting the same object multiple times.
176+ pub fn merge_commits (
177+ & self ,
178+ our_commit : impl Into < gix_hash:: ObjectId > ,
179+ their_commit : impl Into < gix_hash:: ObjectId > ,
180+ labels : gix_merge:: blob:: builtin_driver:: text:: Labels < ' _ > ,
181+ options : crate :: merge:: commit:: Options ,
182+ ) -> Result < crate :: merge:: commit:: Outcome < ' _ > , merge_commits:: Error > {
183+ let mut diff_cache = self . diff_resource_cache_for_tree_diff ( ) ?;
184+ let mut blob_merge = self . merge_resource_cache ( Default :: default ( ) ) ?;
185+ let commit_graph = self . commit_graph_if_enabled ( ) ?;
186+ let mut graph = self . revision_graph ( commit_graph. as_ref ( ) ) ;
187+ let gix_merge:: commit:: Outcome {
188+ tree_merge :
189+ gix_merge:: tree:: Outcome {
190+ tree,
191+ conflicts,
192+ failed_on_first_unresolved_conflict,
193+ } ,
194+ merge_base_tree_id,
195+ merge_bases,
196+ virtual_merge_bases,
197+ } = gix_merge:: commit (
198+ our_commit. into ( ) ,
199+ their_commit. into ( ) ,
200+ labels,
201+ & mut graph,
202+ & mut diff_cache,
203+ & mut blob_merge,
204+ self ,
205+ & mut |id| id. to_owned ( ) . attach ( self ) . shorten_or_id ( ) . to_string ( ) ,
206+ options. into ( ) ,
207+ ) ?;
208+
209+ let validate = self . config . protect_options ( ) ?;
210+ let tree_merge = crate :: merge:: tree:: Outcome {
211+ tree : crate :: object:: tree:: Editor {
212+ inner : tree,
213+ validate,
214+ repo : self ,
215+ } ,
216+ conflicts,
217+ failed_on_first_unresolved_conflict,
218+ } ;
219+ Ok ( crate :: merge:: commit:: Outcome {
220+ tree_merge,
221+ merge_base_tree_id,
222+ merge_bases,
223+ virtual_merge_bases,
224+ } )
225+ }
158226}
0 commit comments