Skip to content

Commit

Permalink
fix!: prefer to receive borrowed gix_command::Context when it's jus…
Browse files Browse the repository at this point in the history
…t passed on.

That way, the clone occours only when needed, without forcing the caller
to pre-emptively clone each time it's called.
  • Loading branch information
Byron committed Oct 31, 2024
1 parent e2ea398 commit 78a5355
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions gix-merge/src/blob/platform/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,15 @@ impl<'parent> PlatformRef<'parent> {
&self,
out: &mut Vec<u8>,
labels: builtin_driver::text::Labels<'_>,
context: gix_command::Context,
context: &gix_command::Context,
) -> Result<(inner::builtin_merge::Pick, Resolution), Error> {
let _span = gix_trace::coarse!(
"gix_merge::blob::PlatformRef::merge()",
current_rela_path = %self.current.rela_path
);
match self.configured_driver() {
Ok(driver) => {
let mut cmd = self.prepare_external_driver(driver.command.clone(), labels, context)?;
let mut cmd = self.prepare_external_driver(driver.command.clone(), labels, context.clone())?;
let status = cmd.status().map_err(|err| Error::SpawnExternalDriver {
cmd: format!("{:?}", cmd.cmd),
source: err,
Expand Down
28 changes: 14 additions & 14 deletions gix-merge/tests/merge/blob/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ mod merge {
);

let mut buf = Vec::new();
let res = platform_ref.merge(&mut buf, default_labels(), Default::default())?;
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
assert_eq!(
res,
(Pick::Ours, Resolution::Conflict),
"it detected the binary buffer, ran the binary merge with default conflict resolution"
);

platform_ref.options.resolve_binary_with = Some(builtin_driver::binary::ResolveWith::Theirs);
let res = platform_ref.merge(&mut buf, default_labels(), Default::default())?;
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
assert_eq!(
res,
(Pick::Theirs, Resolution::Complete),
Expand Down Expand Up @@ -86,7 +86,7 @@ mod merge {
let mut platform_ref = platform.prepare_merge(&db, Default::default())?;
assert_eq!(platform_ref.driver, DriverChoice::BuiltIn(BuiltinDriver::Text));
let mut buf = Vec::new();
let res = platform_ref.merge(&mut buf, default_labels(), Default::default())?;
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
assert_eq!(res, (Pick::Buffer, Resolution::Conflict));
assert_eq!(
buf.as_bstr(),
Expand All @@ -102,7 +102,7 @@ theirs
style: ConflictStyle::Diff3,
marker_size: 3,
};
let res = platform_ref.merge(&mut buf, default_labels(), Default::default())?;
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
assert_eq!(res, (Pick::Buffer, Resolution::Conflict));

assert_eq!(
Expand All @@ -119,7 +119,7 @@ theirs
);

platform_ref.options.text.conflict = builtin_driver::text::Conflict::ResolveWithOurs;
let res = platform_ref.merge(&mut buf, default_labels(), Default::default())?;
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
assert_eq!(
res,
(Pick::Buffer, Resolution::Complete),
Expand All @@ -128,23 +128,23 @@ theirs
assert_eq!(buf.as_bstr(), "ours");

platform_ref.options.text.conflict = builtin_driver::text::Conflict::ResolveWithTheirs;
let res = platform_ref.merge(&mut buf, default_labels(), Default::default())?;
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
assert_eq!(res, (Pick::Buffer, Resolution::Complete));
assert_eq!(buf.as_bstr(), "theirs");

platform_ref.options.text.conflict = builtin_driver::text::Conflict::ResolveWithUnion;
let res = platform_ref.merge(&mut buf, default_labels(), Default::default())?;
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
assert_eq!(res, (Pick::Buffer, Resolution::Complete));
assert_eq!(buf.as_bstr(), "ours\ntheirs");

platform_ref.driver = DriverChoice::BuiltIn(BuiltinDriver::Union);
platform_ref.options.text.conflict = builtin_driver::text::Conflict::default();
let res = platform_ref.merge(&mut buf, default_labels(), Default::default())?;
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
assert_eq!(res, (Pick::Buffer, Resolution::Complete));
assert_eq!(buf.as_bstr(), "ours\ntheirs");

platform_ref.driver = DriverChoice::BuiltIn(BuiltinDriver::Binary);
let res = platform_ref.merge(&mut buf, default_labels(), Default::default())?;
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
assert_eq!(
res,
(Pick::Ours, Resolution::Conflict),
Expand All @@ -163,7 +163,7 @@ theirs
("b\n", Pick::Ancestor, builtin_driver::binary::ResolveWith::Ancestor),
] {
platform_ref.options.resolve_binary_with = Some(resolve);
let res = platform_ref.merge(&mut buf, default_labels(), Default::default())?;
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
assert_eq!(res, (expected_pick, Resolution::Complete));
assert_eq!(platform_ref.buffer_by_pick(res.0).unwrap().as_bstr(), expected);
}
Expand Down Expand Up @@ -202,7 +202,7 @@ theirs

let platform_ref = platform.prepare_merge(&db, Default::default())?;
let mut buf = Vec::new();
let res = platform_ref.merge(&mut buf, default_labels(), Default::default())?;
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
assert_eq!(res, (Pick::Buffer, Resolution::Complete), "merge drivers always merge ");
let mut lines = cleaned_driver_lines(&buf)?;
for tmp_file in lines.by_ref().take(3) {
Expand All @@ -228,7 +228,7 @@ theirs
let id = db.insert("binary\0");
platform.set_resource(id, EntryKind::Blob, "b".into(), ResourceKind::OtherOrTheirs, &db)?;
let platform_ref = platform.prepare_merge(&db, Default::default())?;
let res = platform_ref.merge(&mut buf, default_labels(), Default::default())?;
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
assert_eq!(
res,
(Pick::Buffer, Resolution::Complete),
Expand Down Expand Up @@ -282,7 +282,7 @@ theirs
let platform_ref = platform.prepare_merge(&gix_object::find::Never, Default::default())?;

let mut buf = Vec::new();
let res = platform_ref.merge(&mut buf, Default::default(), Default::default())?;
let res = platform_ref.merge(&mut buf, Default::default(), &Default::default())?;
assert_eq!(
res,
(Pick::Buffer, Resolution::Complete),
Expand Down Expand Up @@ -359,7 +359,7 @@ theirs

let mut out = Vec::new();
let err = platform_ref
.merge(&mut out, Default::default(), Default::default())
.merge(&mut out, Default::default(), &Default::default())
.unwrap_err();
assert!(matches!(err, platform::merge::Error::ResourceTooLarge));

Expand Down

0 comments on commit 78a5355

Please sign in to comment.