apply method
Applies every section in patch. prepare runs the full apply for
each section in memory before any write hits the filesystem, so a
multi-section batch is naturally all-or-nothing. Returns one
HashlineSectionResult per section in the original patch order.
Implementation
Future<HashlinePatcherApplyResult> apply(HashlinePatch patch) async {
// Single-section fast path.
if (patch.sections.length == 1) {
final prepared = await prepare(patch.sections[0]);
return HashlinePatcherApplyResult(sections: [await commit(prepared)]);
}
// Prepare every section first so any failure (stale hash, missing
// file, parse error, in-memory no-op) surfaces before any write.
final prepared = await _prepareAll(patch.sections);
_assertUniqueCanonicalPaths(prepared);
_assertNoneNoop(prepared);
return HashlinePatcherApplyResult(sections: await _commitAll(prepared));
}