Mercurial > hg
diff rust/hg-core/src/dirstate_tree/on_disk.rs @ 47335:ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
When parsing becomes lazy, parse error will potentially happen in more places.
This propagates such errors to callers.
Differential Revision: https://phab.mercurial-scm.org/D10749
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 19 May 2021 13:15:00 +0200 |
parents | 18b3060fe598 |
children | 8d0260d0dbc9 |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate_tree/on_disk.rs Wed May 19 13:15:00 2021 +0200 +++ b/rust/hg-core/src/dirstate_tree/on_disk.rs Wed May 19 13:15:00 2021 +0200 @@ -109,7 +109,10 @@ } /// Unexpected file format found in `.hg/dirstate` with the "v2" format. -pub(crate) struct DirstateV2ParseError; +/// +/// This should only happen if Mercurial is buggy or a repository is corrupted. +#[derive(Debug)] +pub struct DirstateV2ParseError; impl From<DirstateV2ParseError> for HgError { fn from(_: DirstateV2ParseError) -> Self { @@ -295,9 +298,9 @@ // First accumulate serialized nodes in a `Vec` let mut on_disk_nodes = Vec::with_capacity(nodes.len()); for node in nodes { - let children = write_nodes(node.children(), out)?; - let full_path = write_slice::<u8>(node.full_path().as_bytes(), out); - let copy_source = if let Some(source) = node.copy_source() { + let children = write_nodes(node.children()?, out)?; + let full_path = write_slice::<u8>(node.full_path()?.as_bytes(), out); + let copy_source = if let Some(source) = node.copy_source()? { write_slice::<u8>(source.as_bytes(), out) } else { Slice {