dirstate.rs
100 lines
| 2.3 KiB
| application/rls-services+xml
|
RustLexer
Raphaël Gomès
|
r42993 | // 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. | ||||
Raphaël Gomès
|
r53198 | use std::fmt; | ||
Raphaël Gomès
|
r53195 | use crate::dirstate::on_disk::DirstateV2ParseError; | ||
Raphaël Gomès
|
r53198 | use crate::errors; | ||
Simon Sapin
|
r48165 | use crate::revlog::node::NULL_NODE; | ||
Simon Sapin
|
r47337 | use crate::revlog::Node; | ||
Raphaël Gomès
|
r53198 | use crate::utils::hg_path::{HgPath, HgPathBuf, HgPathError}; | ||
Simon Sapin
|
r48830 | use bytes_cast::BytesCast; | ||
Raphaël Gomès
|
r53196 | use entry::DirstateEntry; | ||
Raphaël Gomès
|
r42993 | |||
Raphaël Gomès
|
r42828 | pub mod dirs_multiset; | ||
Raphaël Gomès
|
r53195 | pub mod dirstate_map; | ||
Simon Sapin
|
r48830 | pub mod entry; | ||
Raphaël Gomès
|
r53195 | pub mod on_disk; | ||
pub mod owning; | ||||
Raphaël Gomès
|
r42828 | pub mod parsers; | ||
Raphaël Gomès
|
r53195 | pub mod path_with_basename; | ||
Raphaël Gomès
|
r43565 | pub mod status; | ||
Raphaël Gomès
|
r42828 | |||
Simon Sapin
|
r48768 | #[derive(Debug, PartialEq, Copy, Clone, BytesCast)] | ||
Simon Sapin
|
r47336 | #[repr(C)] | ||
Raphaël Gomès
|
r42993 | pub struct DirstateParents { | ||
Simon Sapin
|
r47337 | pub p1: Node, | ||
pub p2: Node, | ||||
Raphaël Gomès
|
r42828 | } | ||
Simon Sapin
|
r48165 | impl DirstateParents { | ||
pub const NULL: Self = Self { | ||||
p1: NULL_NODE, | ||||
p2: NULL_NODE, | ||||
}; | ||||
Arseniy Alekseyev
|
r50334 | |||
pub fn is_merge(&self) -> bool { | ||||
Raphaël Gomès
|
r50825 | !(self.p2 == NULL_NODE) | ||
Arseniy Alekseyev
|
r50334 | } | ||
Simon Sapin
|
r48165 | } | ||
Simon Sapin
|
r48126 | pub type StateMapIter<'a> = Box< | ||
dyn Iterator< | ||||
Item = Result<(&'a HgPath, DirstateEntry), DirstateV2ParseError>, | ||||
> + Send | ||||
+ 'a, | ||||
>; | ||||
Raphaël Gomès
|
r46185 | |||
Simon Sapin
|
r48126 | pub type CopyMapIter<'a> = Box< | ||
dyn Iterator<Item = Result<(&'a HgPath, &'a HgPath), DirstateV2ParseError>> | ||||
+ Send | ||||
+ 'a, | ||||
>; | ||||
Raphaël Gomès
|
r53198 | |||
#[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), | ||||
} | ||||
} | ||||
} | ||||