Skip to content

Commit c02adc7

Browse files
committed
feat: add Repository::blob_merge_options() to obtain options for merging blobs and Repository::diff_algorithm()
1 parent 9e79ba3 commit c02adc7

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

Diff for: gix/src/repository/config/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ impl crate::Repository {
120120
pub fn object_hash(&self) -> gix_hash::Kind {
121121
self.config.object_hash
122122
}
123+
124+
/// Return the algorithm to perform diffs or merges with.
125+
///
126+
/// In case of merges, a diff is performed under the hood in order to learn which hunks need merging.
127+
#[cfg(feature = "blob-diff")]
128+
pub fn diff_algorithm(&self) -> Result<gix_diff::blob::Algorithm, config::diff::algorithm::Error> {
129+
self.config.diff_algorithm()
130+
}
123131
}
124132

125133
mod branch;

Diff for: gix/src/repository/merge.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::config::cache::util::ApplyLeniencyDefault;
22
use crate::config::tree;
3-
use crate::repository::merge_resource_cache;
3+
use crate::repository::{blob_merge_options, merge_resource_cache};
44
use crate::Repository;
5+
use gix_merge::blob::builtin_driver::text;
56
use std::borrow::Cow;
67

78
/// Merge-utilities
@@ -53,4 +54,29 @@ impl Repository {
5354
let drivers = self.config.merge_drivers()?;
5455
Ok(gix_merge::blob::Platform::new(filter, mode, attrs, drivers, options))
5556
}
57+
58+
/// Return options for use with [`gix_merge::blob::PlatformRef::merge()`].
59+
pub fn blob_merge_options(&self) -> Result<gix_merge::blob::platform::merge::Options, blob_merge_options::Error> {
60+
Ok(gix_merge::blob::platform::merge::Options {
61+
is_virtual_ancestor: false,
62+
resolve_binary_with: None,
63+
text: gix_merge::blob::builtin_driver::text::Options {
64+
diff_algorithm: self.config.diff_algorithm()?,
65+
conflict: text::Conflict::Keep {
66+
style: self
67+
.config
68+
.resolved
69+
.string(&tree::Merge::CONFLICT_STYLE)
70+
.map(|value| {
71+
tree::Merge::CONFLICT_STYLE
72+
.try_into_conflict_style(value)
73+
.with_lenient_default(self.config.lenient_config)
74+
})
75+
.transpose()?
76+
.unwrap_or_default(),
77+
marker_size: text::Conflict::DEFAULT_MARKER_SIZE,
78+
},
79+
},
80+
})
81+
}
5682
}

Diff for: gix/src/repository/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ mod submodule;
5858
mod thread_safe;
5959
mod worktree;
6060

61+
///
62+
#[cfg(feature = "blob-merge")]
63+
pub mod blob_merge_options {
64+
/// The error returned by [Repository::blob_merge_options()](crate::Repository::blob_merge_options()).
65+
#[derive(Debug, thiserror::Error)]
66+
#[allow(missing_docs)]
67+
pub enum Error {
68+
#[error(transparent)]
69+
DiffAlgorithm(#[from] crate::config::diff::algorithm::Error),
70+
#[error(transparent)]
71+
ConflictStyle(#[from] crate::config::key::GenericErrorWithValue),
72+
}
73+
}
74+
6175
///
6276
#[cfg(feature = "blob-merge")]
6377
pub mod merge_resource_cache {

0 commit comments

Comments
 (0)