research-scan: EMPTY_SOURCE_MERGE_MSG const, document unreachable!, .to_owned() (#1)

research-scan: EMPTY_SOURCE_MERGE_MSG, doc unreachable!, .to_owned()

Co-authored-by: Omar Sobh <[email protected]>
Co-committed-by: Omar Sobh <[email protected]>
This commit is contained in:
Omar Sobh
2026-05-05 19:07:00 +00:00
committed by redclawsystems
parent 1bf6cffe0e
commit a0576f60cf
4 changed files with 76 additions and 11 deletions
+10 -8
View File
@@ -7,6 +7,10 @@ use crate::error::OnionError;
use crate::format::{BranchEntry, Codec, NO_PARENT};
use crate::writer::OnionFile;
/// Error message used by every merge entrypoint when the source branch has no
/// new revisions relative to the merge target.
const EMPTY_SOURCE_MERGE_MSG: &str = "source branch has no new revisions to merge";
/// Caller-supplied dataset-level merge resolver.
///
/// Receives `(dataset_path, target_bytes, source_bytes)` and returns the merged bytes.
@@ -146,9 +150,7 @@ impl OnionFile {
.collect();
if source_revs.is_empty() {
return Err(OnionError::Malformed(
"source branch has no new revisions to merge".to_string(),
));
return Err(OnionError::Malformed(EMPTY_SOURCE_MERGE_MSG.to_owned()));
}
// Decompress & collect pages in revision order — later writes win.
@@ -189,9 +191,7 @@ impl OnionFile {
.collect();
if source_revs.is_empty() {
return Err(OnionError::Malformed(
"source branch has no new revisions to merge".to_string(),
));
return Err(OnionError::Malformed(EMPTY_SOURCE_MERGE_MSG.to_owned()));
}
// Collect source delta (latest write per offset)
@@ -297,7 +297,7 @@ impl OnionFile {
if source_delta.is_empty() {
return Err(OnionError::Malformed(
"three-way merge: source has no new changes since the common ancestor".to_string(),
"three-way merge: source has no new changes since the common ancestor".to_owned(),
));
}
@@ -317,7 +317,9 @@ impl OnionFile {
(None, Some(_t)) => continue,
// Both changed → source wins (last-write-wins for conflicts)
(Some(s), Some(_t)) => s.clone(),
(None, None) => unreachable!(),
(None, None) => unreachable!(
"all_offsets is union of source_delta and target_delta keys, so at least one side must be Some"
),
};
merged.insert(*offset, result);
}