comparison rust/hg-core/src/dirstate/status.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 717a94b423b9
children 73ddcedeaadf
comparison
equal deleted inserted replaced
47334:18b3060fe598 47335:ed1583a845d2
7 7
8 //! Rust implementation of dirstate.status (dirstate.py). 8 //! Rust implementation of dirstate.status (dirstate.py).
9 //! It is currently missing a lot of functionality compared to the Python one 9 //! It is currently missing a lot of functionality compared to the Python one
10 //! and will only be triggered in narrow cases. 10 //! and will only be triggered in narrow cases.
11 11
12 use crate::dirstate_tree::on_disk::DirstateV2ParseError;
12 use crate::utils::path_auditor::PathAuditor; 13 use crate::utils::path_auditor::PathAuditor;
13 use crate::{ 14 use crate::{
14 dirstate::SIZE_FROM_OTHER_PARENT, 15 dirstate::SIZE_FROM_OTHER_PARENT,
15 filepatterns::PatternFileWarning, 16 filepatterns::PatternFileWarning,
16 matchers::{get_ignore_function, Matcher, VisitChildrenSet}, 17 matchers::{get_ignore_function, Matcher, VisitChildrenSet},
300 IO(std::io::Error), 301 IO(std::io::Error),
301 /// An invalid path that cannot be represented in Mercurial was found 302 /// An invalid path that cannot be represented in Mercurial was found
302 Path(HgPathError), 303 Path(HgPathError),
303 /// An invalid "ignore" pattern was found 304 /// An invalid "ignore" pattern was found
304 Pattern(PatternError), 305 Pattern(PatternError),
306 /// Corrupted dirstate
307 DirstateV2ParseError(DirstateV2ParseError),
305 } 308 }
306 309
307 pub type StatusResult<T> = Result<T, StatusError>; 310 pub type StatusResult<T> = Result<T, StatusError>;
308 311
309 impl fmt::Display for StatusError { 312 impl fmt::Display for StatusError {
310 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 313 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
311 match self { 314 match self {
312 StatusError::IO(error) => error.fmt(f), 315 StatusError::IO(error) => error.fmt(f),
313 StatusError::Path(error) => error.fmt(f), 316 StatusError::Path(error) => error.fmt(f),
314 StatusError::Pattern(error) => error.fmt(f), 317 StatusError::Pattern(error) => error.fmt(f),
318 StatusError::DirstateV2ParseError(_) => {
319 f.write_str("dirstate-v2 parse error")
320 }
315 } 321 }
316 } 322 }
317 } 323 }
318 324
319 /// Gives information about which files are changed in the working directory 325 /// Gives information about which files are changed in the working directory