##// END OF EJS Templates
rust: make RevlogError AmbiguousPrefix case contain the actual prefix...
rust: make RevlogError AmbiguousPrefix case contain the actual prefix This brings the work started in `652149ed64f0` to its logical conclusion and makes the RevlogError self-sufficient so it can be directly converted to CommandError, without an extra rev text annotation. Without this change, it's confusing that the extra annotation is ignored in most-but-not-all cases.

File last commit:

r53198:79e8118c default
r53240:393ad268 default
Show More
dirstate.rs
100 lines | 2.3 KiB | application/rls-services+xml | RustLexer
// dirstate module
//
// Copyright 2019 Raphaël Gomès <rgomes@octobus.net>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
use std::fmt;
use crate::dirstate::on_disk::DirstateV2ParseError;
use crate::errors;
use crate::revlog::node::NULL_NODE;
use crate::revlog::Node;
use crate::utils::hg_path::{HgPath, HgPathBuf, HgPathError};
use bytes_cast::BytesCast;
use entry::DirstateEntry;
pub mod dirs_multiset;
pub mod dirstate_map;
pub mod entry;
pub mod on_disk;
pub mod owning;
pub mod parsers;
pub mod path_with_basename;
pub mod status;
#[derive(Debug, PartialEq, Copy, Clone, BytesCast)]
#[repr(C)]
pub struct DirstateParents {
pub p1: Node,
pub p2: Node,
}
impl DirstateParents {
pub const NULL: Self = Self {
p1: NULL_NODE,
p2: NULL_NODE,
};
pub fn is_merge(&self) -> bool {
!(self.p2 == NULL_NODE)
}
}
pub type StateMapIter<'a> = Box<
dyn Iterator<
Item = Result<(&'a HgPath, DirstateEntry), DirstateV2ParseError>,
> + Send
+ 'a,
>;
pub type CopyMapIter<'a> = Box<
dyn Iterator<Item = Result<(&'a HgPath, &'a HgPath), DirstateV2ParseError>>
+ Send
+ 'a,
>;
#[derive(Debug, PartialEq)]
pub enum DirstateMapError {
PathNotFound(HgPathBuf),
InvalidPath(HgPathError),
}
impl From<HgPathError> for DirstateMapError {
fn from(error: HgPathError) -> Self {
Self::InvalidPath(error)
}
}
impl fmt::Display for DirstateMapError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
DirstateMapError::PathNotFound(_) => {
f.write_str("expected a value, found none")
}
DirstateMapError::InvalidPath(path_error) => path_error.fmt(f),
}
}
}
#[derive(Debug, derive_more::From)]
pub enum DirstateError {
Map(DirstateMapError),
Common(errors::HgError),
}
impl From<HgPathError> for DirstateError {
fn from(error: HgPathError) -> Self {
Self::Map(DirstateMapError::InvalidPath(error))
}
}
impl fmt::Display for DirstateError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
DirstateError::Map(error) => error.fmt(f),
DirstateError::Common(error) => error.fmt(f),
}
}
}