Debian Codegraph @

rust/hg-core/src/dirstate.rs

raw
1 // dirstate module
2 //
3 // Copyright 2019 Raphaël Gomès <[email protected]>
4 //
5 // This software may be used and distributed according to the terms of the
6 // GNU General Public License version 2 or any later version.
7
8 use std::fmt;
9
10 use bytes_cast::BytesCast;
11 use entry::DirstateEntry;
12
13 use crate::dirstate::on_disk::DirstateV2ParseError;
14 use crate::errors;
15 use crate::revlog::node::NULL_NODE;
16 use crate::revlog::Node;
17 use crate::utils::hg_path::HgPath;
18 use crate::utils::hg_path::HgPathBuf;
19 use crate::utils::hg_path::HgPathError;
20
21 pub mod dirs_multiset;
22 pub mod dirstate_map;
23 pub mod entry;
24 pub mod on_disk;
25 pub mod owning;
26 pub mod parsers;
27 pub mod path_with_basename;
28 pub mod status;
29
30 #[derive(Debug, PartialEq, Copy, Clone, BytesCast)]
31 #[repr(C)]
32 pub struct DirstateParents {
33 pub p1: Node,
34 pub p2: Node,
35 }
36
37 impl DirstateParents {
38 pub const NULL: Self = Self { p1: NULL_NODE, p2: NULL_NODE };
39
40 pub fn is_merge(&self) -> bool {
41 !(self.p2 == NULL_NODE)
42 }
43 }
44
45 pub type StateMapIter<'a> = Box<
46 dyn Iterator<
47 Item = Result<(&'a HgPath, DirstateEntry), DirstateV2ParseError>,
48 > + Send
49 + Sync
50 + 'a,
51 >;
52
53 pub type CopyMapIter<'a> = Box<
54 dyn Iterator<Item = Result<(&'a HgPath, &'a HgPath), DirstateV2ParseError>>
55 + Send
56 + Sync
57 + 'a,
58 >;
59
60 #[derive(Debug, PartialEq)]
61 pub enum DirstateMapError {
62 PathNotFound(HgPathBuf),
63 InvalidPath(HgPathError),
64 }
65
66 impl From<HgPathError> for DirstateMapError {
67 fn from(error: HgPathError) -> Self {
68 Self::InvalidPath(error)
69 }
70 }
71
72 impl fmt::Display for DirstateMapError {
73 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
74 match self {
75 DirstateMapError::PathNotFound(_) => {
76 f.write_str("expected a value, found none")
77 }
78 DirstateMapError::InvalidPath(path_error) => path_error.fmt(f),
79 }
80 }
81 }
82
83 #[derive(Debug, derive_more::From)]
84 pub enum DirstateError {
85 Map(DirstateMapError),
86 Common(errors::HgError),
87 }
88
89 impl From<HgPathError> for DirstateError {
90 fn from(error: HgPathError) -> Self {
91 Self::Map(DirstateMapError::InvalidPath(error))
92 }
93 }
94
95 impl fmt::Display for DirstateError {
96 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
97 match self {
98 DirstateError::Map(error) => error.fmt(f),
99 DirstateError::Common(error) => error.fmt(f),
100 }
101 }
102 }