##// END OF EJS Templates
rust-core: updated copyright notice...
Georges Racinet -
r44455:cb2e2b09 default
parent child Browse files
Show More
@@ -1,173 +1,174 b''
1 // Copyright 2018 Georges Racinet <gracinet@anybox.fr>
1 // Copyright 2018-2020 Georges Racinet <georges.racinet@octobus.net>
2 // and Mercurial contributors
2 3 //
3 4 // This software may be used and distributed according to the terms of the
4 5 // GNU General Public License version 2 or any later version.
5 6 mod ancestors;
6 7 pub mod dagops;
7 8 pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors};
8 9 mod dirstate;
9 10 pub mod discovery;
10 11 pub mod testing; // unconditionally built, for use from integration tests
11 12 pub use dirstate::{
12 13 dirs_multiset::{DirsMultiset, DirsMultisetIter},
13 14 dirstate_map::DirstateMap,
14 15 parsers::{pack_dirstate, parse_dirstate, PARENT_SIZE},
15 16 status::{status, StatusResult},
16 17 CopyMap, CopyMapIter, DirstateEntry, DirstateParents, EntryState,
17 18 StateMap, StateMapIter,
18 19 };
19 20 mod filepatterns;
20 21 pub mod matchers;
21 22 pub mod utils;
22 23
23 24 use crate::utils::hg_path::HgPathBuf;
24 25 pub use filepatterns::{
25 26 build_single_regex, read_pattern_file, PatternSyntax, PatternTuple,
26 27 };
27 28 use std::collections::HashMap;
28 29 use twox_hash::RandomXxHashBuilder64;
29 30
30 31 /// Mercurial revision numbers
31 32 ///
32 33 /// As noted in revlog.c, revision numbers are actually encoded in
33 34 /// 4 bytes, and are liberally converted to ints, whence the i32
34 35 pub type Revision = i32;
35 36
36 37 /// Marker expressing the absence of a parent
37 38 ///
38 39 /// Independently of the actual representation, `NULL_REVISION` is guaranteed
39 40 /// to be smaller that all existing revisions.
40 41 pub const NULL_REVISION: Revision = -1;
41 42
42 43 /// Same as `mercurial.node.wdirrev`
43 44 ///
44 45 /// This is also equal to `i32::max_value()`, but it's better to spell
45 46 /// it out explicitely, same as in `mercurial.node`
46 47 pub const WORKING_DIRECTORY_REVISION: Revision = 0x7fffffff;
47 48
48 49 /// The simplest expression of what we need of Mercurial DAGs.
49 50 pub trait Graph {
50 51 /// Return the two parents of the given `Revision`.
51 52 ///
52 53 /// Each of the parents can be independently `NULL_REVISION`
53 54 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError>;
54 55 }
55 56
56 57 pub type LineNumber = usize;
57 58
58 59 /// Rust's default hasher is too slow because it tries to prevent collision
59 60 /// attacks. We are not concerned about those: if an ill-minded person has
60 61 /// write access to your repository, you have other issues.
61 62 pub type FastHashMap<K, V> = HashMap<K, V, RandomXxHashBuilder64>;
62 63
63 64 #[derive(Clone, Debug, PartialEq)]
64 65 pub enum GraphError {
65 66 ParentOutOfRange(Revision),
66 67 WorkingDirectoryUnsupported,
67 68 }
68 69
69 70 #[derive(Clone, Debug, PartialEq)]
70 71 pub enum DirstateParseError {
71 72 TooLittleData,
72 73 Overflow,
73 74 CorruptedEntry(String),
74 75 Damaged,
75 76 }
76 77
77 78 impl From<std::io::Error> for DirstateParseError {
78 79 fn from(e: std::io::Error) -> Self {
79 80 DirstateParseError::CorruptedEntry(e.to_string())
80 81 }
81 82 }
82 83
83 84 impl ToString for DirstateParseError {
84 85 fn to_string(&self) -> String {
85 86 use crate::DirstateParseError::*;
86 87 match self {
87 88 TooLittleData => "Too little data for dirstate.".to_string(),
88 89 Overflow => "Overflow in dirstate.".to_string(),
89 90 CorruptedEntry(e) => format!("Corrupted entry: {:?}.", e),
90 91 Damaged => "Dirstate appears to be damaged.".to_string(),
91 92 }
92 93 }
93 94 }
94 95
95 96 #[derive(Debug, PartialEq)]
96 97 pub enum DirstatePackError {
97 98 CorruptedEntry(String),
98 99 CorruptedParent,
99 100 BadSize(usize, usize),
100 101 }
101 102
102 103 impl From<std::io::Error> for DirstatePackError {
103 104 fn from(e: std::io::Error) -> Self {
104 105 DirstatePackError::CorruptedEntry(e.to_string())
105 106 }
106 107 }
107 108 #[derive(Debug, PartialEq)]
108 109 pub enum DirstateMapError {
109 110 PathNotFound(HgPathBuf),
110 111 EmptyPath,
111 112 ConsecutiveSlashes,
112 113 }
113 114
114 115 impl ToString for DirstateMapError {
115 116 fn to_string(&self) -> String {
116 117 use crate::DirstateMapError::*;
117 118 match self {
118 119 PathNotFound(_) => "expected a value, found none".to_string(),
119 120 EmptyPath => "Overflow in dirstate.".to_string(),
120 121 ConsecutiveSlashes => {
121 122 "found invalid consecutive slashes in path".to_string()
122 123 }
123 124 }
124 125 }
125 126 }
126 127
127 128 pub enum DirstateError {
128 129 Parse(DirstateParseError),
129 130 Pack(DirstatePackError),
130 131 Map(DirstateMapError),
131 132 IO(std::io::Error),
132 133 }
133 134
134 135 impl From<DirstateParseError> for DirstateError {
135 136 fn from(e: DirstateParseError) -> Self {
136 137 DirstateError::Parse(e)
137 138 }
138 139 }
139 140
140 141 impl From<DirstatePackError> for DirstateError {
141 142 fn from(e: DirstatePackError) -> Self {
142 143 DirstateError::Pack(e)
143 144 }
144 145 }
145 146
146 147 #[derive(Debug)]
147 148 pub enum PatternError {
148 149 UnsupportedSyntax(String),
149 150 }
150 151
151 152 #[derive(Debug)]
152 153 pub enum PatternFileError {
153 154 IO(std::io::Error),
154 155 Pattern(PatternError, LineNumber),
155 156 }
156 157
157 158 impl From<std::io::Error> for PatternFileError {
158 159 fn from(e: std::io::Error) -> Self {
159 160 PatternFileError::IO(e)
160 161 }
161 162 }
162 163
163 164 impl From<DirstateMapError> for DirstateError {
164 165 fn from(e: DirstateMapError) -> Self {
165 166 DirstateError::Map(e)
166 167 }
167 168 }
168 169
169 170 impl From<std::io::Error> for DirstateError {
170 171 fn from(e: std::io::Error) -> Self {
171 172 DirstateError::IO(e)
172 173 }
173 174 }
General Comments 0
You need to be logged in to leave comments. Login now