|
| 1 | +use crate::config::cache::util::ApplyLeniencyDefault; |
| 2 | +use crate::config::tree; |
| 3 | +use crate::repository::merge_resource_cache; |
| 4 | +use crate::Repository; |
| 5 | + |
| 6 | +/// Diff-utilities |
| 7 | +impl Repository { |
| 8 | + /// Create a resource cache that can hold the three resources needed for a three-way merge. `worktree_roots` |
| 9 | + /// determines which side of the merge is read from the worktree, or from which worktree. |
| 10 | + /// |
| 11 | + /// The platform can be used to setup resources and finally perform a merge. |
| 12 | + pub fn merge_resource_cache( |
| 13 | + &self, |
| 14 | + worktree_roots: gix_merge::blob::pipeline::WorktreeRoots, |
| 15 | + ) -> Result<gix_merge::blob::Platform, merge_resource_cache::Error> { |
| 16 | + let index = self.index_or_load_from_head()?; |
| 17 | + let mode = { |
| 18 | + let renormalize = self |
| 19 | + .config |
| 20 | + .resolved |
| 21 | + .boolean(&tree::Merge::RENORMALIZE) |
| 22 | + .map(|res| { |
| 23 | + tree::Merge::RENORMALIZE |
| 24 | + .enrich_error(res) |
| 25 | + .with_lenient_default(self.config.lenient_config) |
| 26 | + }) |
| 27 | + .transpose()? |
| 28 | + .unwrap_or_default(); |
| 29 | + if renormalize { |
| 30 | + gix_merge::blob::pipeline::Mode::Renormalize |
| 31 | + } else { |
| 32 | + gix_merge::blob::pipeline::Mode::ToGit |
| 33 | + } |
| 34 | + }; |
| 35 | + let attrs = self |
| 36 | + .attributes_only( |
| 37 | + &index, |
| 38 | + if worktree_roots.is_unset() { |
| 39 | + gix_worktree::stack::state::attributes::Source::IdMapping |
| 40 | + } else { |
| 41 | + gix_worktree::stack::state::attributes::Source::WorktreeThenIdMapping |
| 42 | + }, |
| 43 | + )? |
| 44 | + .inner; |
| 45 | + let filter = gix_filter::Pipeline::new(self.command_context()?, crate::filter::Pipeline::options(self)?); |
| 46 | + let filter = gix_merge::blob::Pipeline::new(worktree_roots, filter, self.config.merge_pipeline_options()?); |
| 47 | + let options = gix_merge::blob::platform::Options { |
| 48 | + default_driver: self |
| 49 | + .config |
| 50 | + .resolved |
| 51 | + .string(&tree::Merge::DEFAULT) |
| 52 | + .map(|name| name.into_owned()), |
| 53 | + }; |
| 54 | + let drivers = self.config.merge_drivers()?; |
| 55 | + Ok(gix_merge::blob::Platform::new(filter, mode, attrs, drivers, options)) |
| 56 | + } |
| 57 | +} |
0 commit comments