##// END OF EJS Templates
hg-core: add a compilation error if trying to compile outside of Linux...
Raphaël Gomès -
r45029:5a50e8c3 stable draft
parent child Browse files
Show More
@@ -1,144 +1,152
1 1 // Copyright 2018-2020 Georges Racinet <georges.racinet@octobus.net>
2 2 // and Mercurial contributors
3 3 //
4 4 // This software may be used and distributed according to the terms of the
5 5 // GNU General Public License version 2 or any later version.
6 6 mod ancestors;
7 7 pub mod dagops;
8 8 pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors};
9 9 mod dirstate;
10 10 pub mod discovery;
11 11 pub mod testing; // unconditionally built, for use from integration tests
12 12 pub use dirstate::{
13 13 dirs_multiset::{DirsMultiset, DirsMultisetIter},
14 14 dirstate_map::DirstateMap,
15 15 parsers::{pack_dirstate, parse_dirstate, PARENT_SIZE},
16 16 status::{status, StatusResult},
17 17 CopyMap, CopyMapIter, DirstateEntry, DirstateParents, EntryState,
18 18 StateMap, StateMapIter,
19 19 };
20 20 mod filepatterns;
21 21 pub mod matchers;
22 22 pub mod revlog;
23 23 pub use revlog::*;
24 24 pub mod utils;
25 25
26 /// Remove this to see (potential) non-artificial compile failures. MacOS
27 /// *should* compile, but fail to compile tests for example as of 2020-03-06
28 #[cfg(not(target_os = "linux"))]
29 compile_error!(
30 "`hg-core` has only been tested on Linux and will most \
31 likely not behave correctly on other platforms."
32 );
33
26 34 use crate::utils::hg_path::HgPathBuf;
27 35 pub use filepatterns::{
28 36 build_single_regex, read_pattern_file, PatternSyntax, PatternTuple,
29 37 };
30 38 use std::collections::HashMap;
31 39 use twox_hash::RandomXxHashBuilder64;
32 40
33 41 pub type LineNumber = usize;
34 42
35 43 /// Rust's default hasher is too slow because it tries to prevent collision
36 44 /// attacks. We are not concerned about those: if an ill-minded person has
37 45 /// write access to your repository, you have other issues.
38 46 pub type FastHashMap<K, V> = HashMap<K, V, RandomXxHashBuilder64>;
39 47
40 48 #[derive(Clone, Debug, PartialEq)]
41 49 pub enum DirstateParseError {
42 50 TooLittleData,
43 51 Overflow,
44 52 CorruptedEntry(String),
45 53 Damaged,
46 54 }
47 55
48 56 impl From<std::io::Error> for DirstateParseError {
49 57 fn from(e: std::io::Error) -> Self {
50 58 DirstateParseError::CorruptedEntry(e.to_string())
51 59 }
52 60 }
53 61
54 62 impl ToString for DirstateParseError {
55 63 fn to_string(&self) -> String {
56 64 use crate::DirstateParseError::*;
57 65 match self {
58 66 TooLittleData => "Too little data for dirstate.".to_string(),
59 67 Overflow => "Overflow in dirstate.".to_string(),
60 68 CorruptedEntry(e) => format!("Corrupted entry: {:?}.", e),
61 69 Damaged => "Dirstate appears to be damaged.".to_string(),
62 70 }
63 71 }
64 72 }
65 73
66 74 #[derive(Debug, PartialEq)]
67 75 pub enum DirstatePackError {
68 76 CorruptedEntry(String),
69 77 CorruptedParent,
70 78 BadSize(usize, usize),
71 79 }
72 80
73 81 impl From<std::io::Error> for DirstatePackError {
74 82 fn from(e: std::io::Error) -> Self {
75 83 DirstatePackError::CorruptedEntry(e.to_string())
76 84 }
77 85 }
78 86 #[derive(Debug, PartialEq)]
79 87 pub enum DirstateMapError {
80 88 PathNotFound(HgPathBuf),
81 89 EmptyPath,
82 90 ConsecutiveSlashes,
83 91 }
84 92
85 93 impl ToString for DirstateMapError {
86 94 fn to_string(&self) -> String {
87 95 use crate::DirstateMapError::*;
88 96 match self {
89 97 PathNotFound(_) => "expected a value, found none".to_string(),
90 98 EmptyPath => "Overflow in dirstate.".to_string(),
91 99 ConsecutiveSlashes => {
92 100 "found invalid consecutive slashes in path".to_string()
93 101 }
94 102 }
95 103 }
96 104 }
97 105
98 106 pub enum DirstateError {
99 107 Parse(DirstateParseError),
100 108 Pack(DirstatePackError),
101 109 Map(DirstateMapError),
102 110 IO(std::io::Error),
103 111 }
104 112
105 113 impl From<DirstateParseError> for DirstateError {
106 114 fn from(e: DirstateParseError) -> Self {
107 115 DirstateError::Parse(e)
108 116 }
109 117 }
110 118
111 119 impl From<DirstatePackError> for DirstateError {
112 120 fn from(e: DirstatePackError) -> Self {
113 121 DirstateError::Pack(e)
114 122 }
115 123 }
116 124
117 125 #[derive(Debug)]
118 126 pub enum PatternError {
119 127 UnsupportedSyntax(String),
120 128 }
121 129
122 130 #[derive(Debug)]
123 131 pub enum PatternFileError {
124 132 IO(std::io::Error),
125 133 Pattern(PatternError, LineNumber),
126 134 }
127 135
128 136 impl From<std::io::Error> for PatternFileError {
129 137 fn from(e: std::io::Error) -> Self {
130 138 PatternFileError::IO(e)
131 139 }
132 140 }
133 141
134 142 impl From<DirstateMapError> for DirstateError {
135 143 fn from(e: DirstateMapError) -> Self {
136 144 DirstateError::Map(e)
137 145 }
138 146 }
139 147
140 148 impl From<std::io::Error> for DirstateError {
141 149 fn from(e: std::io::Error) -> Self {
142 150 DirstateError::IO(e)
143 151 }
144 152 }
General Comments 0
You need to be logged in to leave comments. Login now